Copy一份javax.annotation.Resource源码到Redkale中,因JDK9中java.base模块中不包含javax.annotation.Resource
This commit is contained in:
36
src/javax/annotation/Resource.java
Normal file
36
src/javax/annotation/Resource.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package javax.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since Common Annotations 1.0
|
||||||
|
*/
|
||||||
|
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Resource {
|
||||||
|
public enum AuthenticationType {
|
||||||
|
CONTAINER,
|
||||||
|
APPLICATION
|
||||||
|
}
|
||||||
|
public String name() default "";
|
||||||
|
/**
|
||||||
|
* Uses generics since Common Annotations 1.2.
|
||||||
|
*/
|
||||||
|
public Class<?> type() default Object.class;
|
||||||
|
public AuthenticationType authenticationType() default AuthenticationType.CONTAINER;
|
||||||
|
public boolean shareable() default true;
|
||||||
|
public String description() default "";
|
||||||
|
public String mappedName() default "";
|
||||||
|
/**
|
||||||
|
* @since Common Annotations 1.1
|
||||||
|
*/
|
||||||
|
public String lookup() default "";
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ import org.redkale.util.AnyValue.DefaultAnyValue;
|
|||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
import org.redkale.watch.*;
|
import org.redkale.watch.*;
|
||||||
import org.w3c.dom.*;
|
import org.w3c.dom.*;
|
||||||
|
import sun.misc.Signal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -277,6 +278,20 @@ public final class Application {
|
|||||||
logger.log(Level.INFO, Transport.class.getSimpleName() + " configure bufferCapacity = " + bufferCapacity + "; bufferPoolSize = " + bufferPoolSize + "; threads = " + threads + ";");
|
logger.log(Level.INFO, Transport.class.getSimpleName() + " configure bufferCapacity = " + bufferCapacity + "; bufferPoolSize = " + bufferPoolSize + "; threads = " + threads + ";");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (transportGroup == null) {
|
||||||
|
final AtomicInteger counter = new AtomicInteger();
|
||||||
|
transportExec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 8, (Runnable r) -> {
|
||||||
|
Thread t = new Thread(r);
|
||||||
|
t.setDaemon(true);
|
||||||
|
t.setName("Transport-Thread-" + counter.incrementAndGet());
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
transportGroup = AsynchronousChannelGroup.withCachedThreadPool(transportExec, 1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.transportFactory = new TransportFactory(transportExec, transportPool, transportGroup, strategy);
|
this.transportFactory = new TransportFactory(transportExec, transportPool, transportGroup, strategy);
|
||||||
Thread.currentThread().setContextClassLoader(this.classLoader);
|
Thread.currentThread().setContextClassLoader(this.classLoader);
|
||||||
this.serverClassLoader = new RedkaleClassLoader(this.classLoader);
|
this.serverClassLoader = new RedkaleClassLoader(this.classLoader);
|
||||||
@@ -593,10 +608,38 @@ public final class Application {
|
|||||||
runServers(timecd, others);
|
runServers(timecd, others);
|
||||||
runServers(timecd, watchs); //必须在所有服务都启动后再启动WATCH服务
|
runServers(timecd, watchs); //必须在所有服务都启动后再启动WATCH服务
|
||||||
timecd.await();
|
timecd.await();
|
||||||
|
if (!singletonrun) signalHandle();
|
||||||
logger.info(this.getClass().getSimpleName() + " started in " + (System.currentTimeMillis() - startTime) + " ms\r\n");
|
logger.info(this.getClass().getSimpleName() + " started in " + (System.currentTimeMillis() - startTime) + " ms\r\n");
|
||||||
if (!singletonrun) this.serversLatch.await();
|
if (!singletonrun) this.serversLatch.await();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void signalHandle() {
|
||||||
|
//http://www.comptechdoc.org/os/linux/programming/linux_pgsignals.html
|
||||||
|
String[] sigs = new String[]{"HUP", "TERM", "INT", "QUIT", "KILL", "TSTP", "USR1", "USR2", "STOP"};
|
||||||
|
List<sun.misc.Signal> list = new ArrayList<>();
|
||||||
|
for (String sig : sigs) {
|
||||||
|
try {
|
||||||
|
list.add(new sun.misc.Signal(sig));
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sun.misc.SignalHandler handler = new sun.misc.SignalHandler() {
|
||||||
|
|
||||||
|
private volatile boolean runed;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(Signal sig) {
|
||||||
|
if (runed) return;
|
||||||
|
runed = true;
|
||||||
|
logger.info(Application.this.getClass().getSimpleName() + " stoped\r\n");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (Signal sig : list) {
|
||||||
|
Signal.handle(sig, handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void runServers(CountDownLatch timecd, final List<AnyValue> serconfs) throws Exception {
|
private void runServers(CountDownLatch timecd, final List<AnyValue> serconfs) throws Exception {
|
||||||
this.servicecdl = new CountDownLatch(serconfs.size());
|
this.servicecdl = new CountDownLatch(serconfs.size());
|
||||||
|
|||||||
Reference in New Issue
Block a user