Repository: tomee
Updated Branches:
  refs/heads/master 85635cd8c -> 022d8fa45


TOMEE-2044 avoid singleton when we dont need it


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/022d8fa4
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/022d8fa4
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/022d8fa4

Branch: refs/heads/master
Commit: 022d8fa45ae849db5832777ebc3857969db30cba
Parents: 85635cd
Author: rmannibucau <rmannibu...@apache.org>
Authored: Thu Jun 1 18:34:04 2017 +0200
Committer: rmannibucau <rmannibu...@apache.org>
Committed: Thu Jun 1 18:34:04 2017 +0200

----------------------------------------------------------------------
 .../openejb/server/ejbd/KeepAliveServer.java    |  4 +--
 .../openejb/server/ServerServiceFilter.java     |  7 ++++-
 .../openejb/server/ServiceAccessController.java |  2 +-
 .../apache/openejb/server/ServiceDaemon.java    | 13 ++++++---
 .../org/apache/openejb/server/ServicePool.java  | 16 ++++++++++-
 .../org/apache/openejb/server/Unwrappable.java  | 21 ++++++++++++++
 .../openejb/server/UnwrappbleServerService.java | 29 ++++++++++++++++++++
 7 files changed, 83 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/022d8fa4/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
 
b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
index c25b988..d41d36f 100644
--- 
a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
+++ 
b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java
@@ -18,10 +18,10 @@ package org.apache.openejb.server.ejbd;
 
 import org.apache.openejb.client.FlushableGZIPOutputStream;
 import org.apache.openejb.client.KeepAliveStyle;
-import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.server.ServerService;
 import org.apache.openejb.server.ServiceException;
 import org.apache.openejb.server.ServicePool;
+import org.apache.openejb.server.Unwrappable;
 import org.apache.openejb.server.context.RequestInfos;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
@@ -161,7 +161,7 @@ public class KeepAliveServer implements ServerService {
     private BlockingQueue<Runnable> getQueue() {
         if (this.threadQueue == null) {
             // this can be null if timer fires before service is fully 
initialized
-            final ServicePool incoming = 
SystemInstance.get().getComponent(ServicePool.class);
+            final ServicePool incoming = Unwrappable.class.isInstance(service) 
? Unwrappable.class.cast(service).unwrap(ServicePool.class) : null;
             if (incoming == null) {
                 return null;
             }

http://git-wip-us.apache.org/repos/asf/tomee/blob/022d8fa4/server/openejb-server/src/main/java/org/apache/openejb/server/ServerServiceFilter.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-server/src/main/java/org/apache/openejb/server/ServerServiceFilter.java
 
b/server/openejb-server/src/main/java/org/apache/openejb/server/ServerServiceFilter.java
index 66d74f9..0835696 100644
--- 
a/server/openejb-server/src/main/java/org/apache/openejb/server/ServerServiceFilter.java
+++ 
b/server/openejb-server/src/main/java/org/apache/openejb/server/ServerServiceFilter.java
@@ -29,7 +29,7 @@ import java.util.Properties;
  *
  * @version $Rev$ $Date$
  */
-public class ServerServiceFilter implements ServerService {
+public class ServerServiceFilter extends UnwrappbleServerService {
 
     @Managed
     private final ServerService service;
@@ -77,4 +77,9 @@ public class ServerServiceFilter implements ServerService {
     public void init(final Properties props) throws Exception {
         service.init(props);
     }
+
+    @Override
+    protected Object getDelegate() {
+        return service;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/022d8fa4/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
 
b/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
index 037ddce..da6e0d7 100644
--- 
a/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
+++ 
b/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceAccessController.java
@@ -38,7 +38,7 @@ import java.util.Properties;
 import java.util.StringTokenizer;
 
 @Managed
-public class ServiceAccessController extends ServerServiceFilter {
+public class ServiceAccessController extends ServerServiceFilter implements 
Unwrappable {
 
     private final Event rejections = new Event();
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/022d8fa4/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
 
b/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
index cd291b5..4d50421 100644
--- 
a/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
+++ 
b/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
@@ -24,6 +24,9 @@ import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.PropertyPlaceHolderHelper;
 import org.apache.openejb.util.StringTemplate;
 
+import javax.net.ServerSocketFactory;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -43,13 +46,10 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
-import javax.net.ServerSocketFactory;
-import javax.net.ssl.SSLServerSocket;
-import javax.net.ssl.SSLServerSocketFactory;
 
 @SuppressWarnings("UnusedDeclaration")
 @Managed
-public class ServiceDaemon implements ServerService {
+public class ServiceDaemon extends UnwrappbleServerService {
 
     private static final Logger log = 
Logger.getInstance(LogCategory.OPENEJB_SERVER, ServiceDaemon.class);
 
@@ -268,6 +268,11 @@ public class ServiceDaemon implements ServerService {
         return this.next.getName();
     }
 
+    @Override
+    protected Object getDelegate() {
+        return next;
+    }
+
     private static class SocketListener implements Runnable {
         private final ServerService serverService;
         private final ServerSocket serverSocket;

http://git-wip-us.apache.org/repos/asf/tomee/blob/022d8fa4/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java
 
b/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java
index 0dc8bbe..66e415b 100644
--- 
a/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java
+++ 
b/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java
@@ -26,6 +26,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.Socket;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Properties;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.RejectedExecutionHandler;
@@ -165,7 +167,11 @@ public class ServicePool extends ServerServiceFilter {
                 }
             });
 
-        SystemInstance.get().setComponent(ServicePool.class, this);
+        Registry registry = SystemInstance.get().getComponent(Registry.class);
+        if (registry == null) {
+            registry = new Registry();
+            SystemInstance.get().setComponent(Registry.class, registry);
+        }
 
         if (log.isInfoEnabled()) {
             log.info(String.format("Created ServicePool '%1$s' with (%2$s) 
core threads, limited to (%3$s) threads with a queue of (%4$s)", getName(), c, 
t, q));
@@ -354,4 +360,12 @@ public class ServicePool extends ServerServiceFilter {
             }
         }
     }
+
+    public static class Registry {
+        private final Collection<ServicePool> pools = new ArrayList<>();
+
+        public Collection<ServicePool> getPools() {
+            return pools;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/022d8fa4/server/openejb-server/src/main/java/org/apache/openejb/server/Unwrappable.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-server/src/main/java/org/apache/openejb/server/Unwrappable.java
 
b/server/openejb-server/src/main/java/org/apache/openejb/server/Unwrappable.java
new file mode 100644
index 0000000..e68c42f
--- /dev/null
+++ 
b/server/openejb-server/src/main/java/org/apache/openejb/server/Unwrappable.java
@@ -0,0 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.server;
+
+public interface Unwrappable {
+    <T> T unwrap(Class<T> type);
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/022d8fa4/server/openejb-server/src/main/java/org/apache/openejb/server/UnwrappbleServerService.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-server/src/main/java/org/apache/openejb/server/UnwrappbleServerService.java
 
b/server/openejb-server/src/main/java/org/apache/openejb/server/UnwrappbleServerService.java
new file mode 100644
index 0000000..96d18f2
--- /dev/null
+++ 
b/server/openejb-server/src/main/java/org/apache/openejb/server/UnwrappbleServerService.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.server;
+
+public abstract class UnwrappbleServerService implements ServerService, 
Unwrappable {
+    @Override
+    public <T> T unwrap(final Class<T> type) {
+        if (type.isAssignableFrom(getClass())) {
+            return type.cast(this);
+        }
+        return Unwrappable.class.isInstance(getDelegate()) ? 
Unwrappable.class.cast(getDelegate()).unwrap(type) : null;
+    }
+
+    protected abstract Object getDelegate();
+}

Reply via email to