diff --git a/src/javax/annotation/Resource.java b/src/javax/annotation/Resource.java new file mode 100644 index 000000000..a575e0369 --- /dev/null +++ b/src/javax/annotation/Resource.java @@ -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 ""; +} diff --git a/src/org/redkale/boot/Application.java b/src/org/redkale/boot/Application.java index e2257444e..f9b8c4c62 100644 --- a/src/org/redkale/boot/Application.java +++ b/src/org/redkale/boot/Application.java @@ -32,6 +32,7 @@ import org.redkale.util.AnyValue.DefaultAnyValue; import org.redkale.util.*; import org.redkale.watch.*; 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 + ";"); } } + 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); Thread.currentThread().setContextClassLoader(this.classLoader); this.serverClassLoader = new RedkaleClassLoader(this.classLoader); @@ -593,10 +608,38 @@ public final class Application { runServers(timecd, others); runServers(timecd, watchs); //必须在所有服务都启动后再启动WATCH服务 timecd.await(); + if (!singletonrun) signalHandle(); logger.info(this.getClass().getSimpleName() + " started in " + (System.currentTimeMillis() - startTime) + " ms\r\n"); 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 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") private void runServers(CountDownLatch timecd, final List serconfs) throws Exception { this.servicecdl = new CountDownLatch(serconfs.size());