Return-Path: X-Original-To: apmail-openejb-commits-archive@www.apache.org Delivered-To: apmail-openejb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4ADE0929E for ; Fri, 24 Feb 2012 16:14:18 +0000 (UTC) Received: (qmail 96329 invoked by uid 500); 24 Feb 2012 16:14:18 -0000 Delivered-To: apmail-openejb-commits-archive@openejb.apache.org Received: (qmail 96307 invoked by uid 500); 24 Feb 2012 16:14:18 -0000 Mailing-List: contact commits-help@openejb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openejb.apache.org Delivered-To: mailing list commits@openejb.apache.org Received: (qmail 96299 invoked by uid 99); 24 Feb 2012 16:14:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Feb 2012 16:14:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Feb 2012 16:14:08 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5A09523889ED for ; Fri, 24 Feb 2012 16:13:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1293319 - in /openejb/trunk/openejb: container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ container/openejb-core/src/main/java/org/apache/openejb/config/ container/openejb-core/src/main/java/org/apache/openejb/core/ti... Date: Fri, 24 Feb 2012 16:13:45 -0000 To: commits@openejb.apache.org From: andygumbrecht@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120224161346.5A09523889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: andygumbrecht Date: Fri Feb 24 16:13:44 2012 New Revision: 1293319 URL: http://svn.apache.org/viewvc?rev=1293319&view=rev Log: Added finals, overrides and cleanup. Fixed several logging crashes on debug level due to empty {}. ServicePool reduce logging on IO error and force Runnable. SocketConnectionFactory only needs to check keepAliveStyle once. KeepAliveServer remove logging on socket issues and cleanup. Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/DefaultTimerThreadPoolAdapter.java openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Activator.java openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbServer.java openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/Server.java openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java (original) +++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java Fri Feb 24 16:13:44 2012 @@ -138,7 +138,7 @@ public class ReloadableEntityManagerFact throw new OpenEJBException("can't register the mbean for the entity manager factory " + getPUname(), e); } catch (NoClassDefFoundError ncdfe) { objectName = null; - LOGGER.error("can't register the mbean for the entity manager factory {}", getPUname()); + LOGGER.error("can't register the mbean for the entity manager factory {0}", getPUname()); } } Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java (original) +++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/MBeanDeployer.java Fri Feb 24 16:13:44 2012 @@ -131,7 +131,7 @@ public class MBeanDeployer implements Dy String listProp = SystemInstance.get().getOptions().get(OPENEJB_MBEAN_CLASSES_PROPERTY, (String) null); if (OPENEJB_MBEAN_FORCE_FINDER.equals(listProp)) { // the classfinder costs too much to be used by default - logger.debug("loading mbeans using an annotation finder, you should maybe adjust {} system property", + logger.debug("loading mbeans using an annotation finder, you should maybe adjust {0} system property", OPENEJB_MBEAN_CLASSES_PROPERTY); List> list = Collections.emptyList(); try { Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/DefaultTimerThreadPoolAdapter.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/DefaultTimerThreadPoolAdapter.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/DefaultTimerThreadPoolAdapter.java (original) +++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/timer/DefaultTimerThreadPoolAdapter.java Fri Feb 24 16:13:44 2012 @@ -17,11 +17,6 @@ package org.apache.openejb.core.timer; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.ThreadPoolExecutor; - import org.apache.openejb.loader.SystemInstance; import org.apache.openejb.util.DaemonThreadFactory; import org.apache.openejb.util.LogCategory; @@ -29,6 +24,13 @@ import org.apache.openejb.util.Logger; import org.quartz.SchedulerConfigException; import org.quartz.spi.ThreadPool; +import java.util.concurrent.Executor; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + /** * @version $Rev$ $Date$ */ @@ -44,28 +46,49 @@ public class DefaultTimerThreadPoolAdapt private final Object threadAvailableLock = new Object(); - private boolean threadPoolExecutorUsed; + private final boolean threadPoolExecutorUsed; public DefaultTimerThreadPoolAdapter() { - executor = SystemInstance.get().getComponent(Executor.class); - if (executor == null) { - executor = Executors.newFixedThreadPool(10, new DaemonThreadFactory(DefaultTimerThreadPoolAdapter.class)); - SystemInstance.get().setComponent(Executor.class, executor); + this.executor = SystemInstance.get().getComponent(Executor.class); + + if (this.executor == null) { + final int size = Integer.parseInt(SystemInstance.get().getProperty("openejb.timer.pool.size", "2")); + this.executor = new ThreadPoolExecutor(2 + , size + , 60L + , TimeUnit.SECONDS + , new LinkedBlockingQueue(size) + , new DaemonThreadFactory(DefaultTimerThreadPoolAdapter.class) + , new RejectedExecutionHandler() { + @Override + public void rejectedExecution(final Runnable r, final ThreadPoolExecutor tpe) { + try { + tpe.getQueue().put(r); + } catch (InterruptedException e) { + throw new RejectedExecutionException("Interrupted waiting for executor slot"); + } + } + } + ); + ((ThreadPoolExecutor) this.executor).allowCoreThreadTimeOut(true); + SystemInstance.get().setComponent(Executor.class, this.executor); } - threadPoolExecutorUsed = executor instanceof ThreadPoolExecutor; - if (!threadPoolExecutorUsed) { - logger.warning("Unrecognized ThreadPool implementation [" + executor.getClass().getName() + "] is used, EJB Timer service may not work correctly"); + + this.threadPoolExecutorUsed = (this.executor instanceof ThreadPoolExecutor); + + if (!this.threadPoolExecutorUsed) { + logger.warning("Unrecognized ThreadPool implementation [" + this.executor.getClass().getName() + "] is used, EJB Timer service may not work correctly"); } } -// @Override + @Override public int blockForAvailableThreads() { - if (threadPoolExecutorUsed) { - ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor; - synchronized (threadAvailableLock) { + if (this.threadPoolExecutorUsed) { + final ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) this.executor; + synchronized (this.threadAvailableLock) { while ((threadPoolExecutor.getMaximumPoolSize() - threadPoolExecutor.getActiveCount()) < 1 && !threadPoolExecutor.isShutdown()) { try { - threadAvailableLock.wait(500L); + this.threadAvailableLock.wait(500L); } catch (InterruptedException ignore) { } } @@ -76,20 +99,28 @@ public class DefaultTimerThreadPoolAdapt } } -// @Override - public void setInstanceId(String instanceId) { + @Override + public void setInstanceId(final String instanceId) { this.instanceId = instanceId; } -// @Override - public void setInstanceName(String instanceName) { + @Override + public void setInstanceName(final String instanceName) { this.instanceName = instanceName; } + public String getInstanceId() { + return this.instanceId; + } + + public String getInstanceName() { + return this.instanceName; + } + @Override public int getPoolSize() { - if (threadPoolExecutorUsed) { - return ((ThreadPoolExecutor) executor).getPoolSize(); + if (this.threadPoolExecutorUsed) { + return ((ThreadPoolExecutor) this.executor).getPoolSize(); } else { return 1; } @@ -100,18 +131,18 @@ public class DefaultTimerThreadPoolAdapt } @Override - public boolean runInThread(Runnable runnable) { + public boolean runInThread(final Runnable runnable) { try { - executor.execute(runnable); + this.executor.execute(runnable); return true; } catch (RejectedExecutionException e) { - logger.error("Fail to executor timer task", e); + logger.error("Failed to execute timer task", e); return false; } } @Override - public void shutdown(boolean arg0) { + public void shutdown(final boolean arg0) { //TODO Seems we should never try to shutdown the thread pool, as it is shared in global scope } Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java (original) +++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/URLs.java Fri Feb 24 16:13:44 2012 @@ -33,10 +33,10 @@ import org.apache.xbean.finder.UrlSet; public class URLs { public static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB, URLs.class.getPackage().getName()); - public static File toFile(URL url) { + public static File toFile(final URL url) { if ("jar".equals(url.getProtocol())) { try { - String spec = url.getFile(); + final String spec = url.getFile(); int separator = spec.indexOf('!'); /* @@ -55,15 +55,15 @@ public class URLs { } } - public static String toFilePath(URL url) { + public static String toFilePath(final URL url) { return toFile(url).getAbsolutePath(); } - public static UrlSet cullSystemAndOpenEJBJars(UrlSet original) throws IOException { + public static UrlSet cullSystemAndOpenEJBJars(final UrlSet original) throws IOException { return cullSystemJars(cullOpenEJBJars(original)); } - public static UrlSet cullSystemJars(UrlSet original) throws IOException { + public static UrlSet cullSystemJars(final UrlSet original) throws IOException { UrlSet urls = new UrlSet(original.getUrls()); urls = urls.exclude(ClassLoader.getSystemClassLoader().getParent()); urls = urls.excludeJavaExtDirs(); @@ -71,14 +71,14 @@ public class URLs { urls = urls.excludeJavaHome(); urls = urls.excludePaths(System.getProperty("sun.boot.class.path", "")); urls = urls.exclude(".*/JavaVM.framework/.*"); - if (LOGGER.isDebugEnabled()) LOGGER.debug("Cullled {} system urls from set", original.size() - urls.size()); + if (LOGGER.isDebugEnabled()) LOGGER.debug("Culled {0} system urls from set", original.size() - urls.size()); return urls; } - public static UrlSet cullOpenEJBJars(UrlSet original) throws IOException { + public static UrlSet cullOpenEJBJars(final UrlSet original) throws IOException { UrlSet urls = new UrlSet(original.getUrls()); urls = urls.exclude(".*openejb.*"); - if (LOGGER.isDebugEnabled()) LOGGER.debug("Cullled {} OpenEJB urls from set", original.size() - urls.size()); + if (LOGGER.isDebugEnabled()) LOGGER.debug("Culled {0} OpenEJB urls from set", original.size() - urls.size()); return urls; } Modified: openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java (original) +++ openejb/trunk/openejb/examples/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java Fri Feb 24 16:13:44 2012 @@ -33,7 +33,7 @@ public class Observer { public void saveDate(@Observes Date date) { dates.add(date); - LOGGER.info("received date '{}'", date); + LOGGER.info("received date '{0}'", date); } public List getDates() { Modified: openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Activator.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Activator.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Activator.java (original) +++ openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Activator.java Fri Feb 24 16:13:44 2012 @@ -41,15 +41,16 @@ public class Activator implements Bundle private OpenEJBInstance openejb; private Object serviceManager; - public void start(BundleContext context) throws Exception { - LOGGER.info("Starting OpenEJB for bundle #{}", context.getBundle().getBundleId()); + @Override + public void start(final BundleContext context) throws Exception { + LOGGER.info("Starting OpenEJB for bundle #{0}", context.getBundle().getBundleId()); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); openejb = new OpenEJBInstance(); OpenEJBBundleContextHolder.set(context); - Properties env = new Properties(); + final Properties env = new Properties(); // env.setProperty("openejb.embedded", "true"); // default, but to remember that the setting exists env.setProperty("openejb.loader", "context"); @@ -72,7 +73,7 @@ public class Activator implements Bundle context.addBundleListener(new Deployer(this)); } - public synchronized void checkServiceManager(BundleContext context) { + public synchronized void checkServiceManager(final BundleContext context) { if (serviceManager != null) { // already started return; } @@ -100,14 +101,15 @@ public class Activator implements Bundle } - private static ServiceTracker getServiceManager(BundleContext context) throws InterruptedException { - ServiceTracker serviceManagerTracker = new ServiceTracker(context, SERVICE_MANAGER_NAME, null); + private static ServiceTracker getServiceManager(final BundleContext context) throws InterruptedException { + final ServiceTracker serviceManagerTracker = new ServiceTracker(context, SERVICE_MANAGER_NAME, null); serviceManagerTracker.open(); serviceManagerTracker.waitForService(TRACKER_TIMEOUT); return serviceManagerTracker; } - public void stop(BundleContext context) throws Exception { + @Override + public void stop(final BundleContext context) throws Exception { LOGGER.info("Stopping OpenEJB"); try { @@ -121,9 +123,10 @@ public class Activator implements Bundle OpenEJB.destroy(); } - private static void invoke(Object serviceManager, String name) throws OpenEJBException, InvocationTargetException, IllegalAccessException { + private static void invoke(final Object serviceManager, final String name) throws OpenEJBException, InvocationTargetException, IllegalAccessException { if (serviceManager == null) { - LOGGER.warn("can't invoke method {} since the service manager is null", name); + LOGGER.warn("can't invoke method {0} since the service manager is null", name); + return; } Class current = serviceManager.getClass(); Modified: openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java (original) +++ openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java Fri Feb 24 16:13:44 2012 @@ -63,7 +63,7 @@ public class Deployer implements BundleL private final Activator openejbActivator; - public Deployer(Activator activator) { + public Deployer(final Activator activator) { openejbActivator = activator; INSTANCE = this; } @@ -72,7 +72,8 @@ public class Deployer implements BundleL return INSTANCE; } - public void bundleChanged(BundleEvent event) { + @Override + public void bundleChanged(final BundleEvent event) { openejbActivator.checkServiceManager(OpenEJBBundleContextHolder.get()); switch (event.getType()) { case BundleEvent.STARTED: @@ -95,14 +96,14 @@ public class Deployer implements BundleL } catch (NullPointerException npe) { // can happen when shutting down an OSGi server // because of all stop events - LOGGER.warn("can't undeploy bundle #{}", event.getBundle().getBundleId()); + LOGGER.warn("can't undeploy bundle #{0}", event.getBundle().getBundleId()); } deploy(event.getBundle()); break; } } - private void deploy(Bundle bundle) { + private void deploy(final Bundle bundle) { final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); final ClassLoader osgiCl = new OSGIClassLoader(bundle, OpenEJBBundleContextHolder.get().getBundle()); Thread.currentThread().setContextClassLoader(osgiCl); @@ -114,7 +115,7 @@ public class Deployer implements BundleL if (context == null && contexts.containsKey(bundle)) { context = contexts.get(bundle); } else if (context == null) { - LOGGER.warn("can't get bundle context of bundle {}", bundle.getBundleId()); + LOGGER.warn("can't get bundle context of bundle {0}", bundle.getBundleId()); return; } @@ -129,11 +130,11 @@ public class Deployer implements BundleL } if (bundleDump == null || !bundleDump.exists()) { - LOGGER.warn("can't find bundle {}", bundle.getBundleId()); + LOGGER.warn("can't find bundle {0}", bundle.getBundleId()); return; } - LOGGER.info("looking bundle {} in {}", bundle.getBundleId(), bundleDump); + LOGGER.info("looking bundle {0} in {1}", bundle.getBundleId(), bundleDump); final AppModule appModule = new OSGiDeploymentLoader(bundle).load(bundleDump); LOGGER.info("deploying bundle #" + bundle.getBundleId() + " as an EJBModule"); @@ -162,7 +163,7 @@ public class Deployer implements BundleL } } - private static File findEquinoxJar(BundleContext bundleContext) { + private static File findEquinoxJar(final BundleContext bundleContext) { final File root = bundleContext.getDataFile("").getParentFile(); int idx = 0; File out; @@ -175,7 +176,7 @@ public class Deployer implements BundleL return out; } - private static File findFelixJar(BundleContext bundleContext) { + private static File findFelixJar(final BundleContext bundleContext) { final File root = bundleContext.getDataFile("").getParentFile(); int min = 0; int max = 0; @@ -194,9 +195,9 @@ public class Deployer implements BundleL return out; } - private void undeploy(Bundle bundle) { + private void undeploy(final Bundle bundle) { if (registrations.containsKey(bundle)) { - for (ServiceRegistration registration : registrations.get(bundle)) { + for (final ServiceRegistration registration : registrations.get(bundle)) { try { registration.unregister(); } catch (IllegalStateException ise) { @@ -208,20 +209,20 @@ public class Deployer implements BundleL if (paths.containsKey(bundle)) { try { - Assembler assembler = SystemInstance.get().getComponent(Assembler.class); + final Assembler assembler = SystemInstance.get().getComponent(Assembler.class); if (assembler != null) { // openejb stopped before bundles when shuttind down the OSGi container assembler.destroyApplication(paths.remove(bundle)); } } catch (IllegalStateException ise) { - LOGGER.error("Can't undeploy bundle #{}", bundle.getBundleId()); + LOGGER.error("Can't undeploy bundle #{0}", bundle.getBundleId()); } catch (UndeployException e) { - LOGGER.error("Can't undeploy bundle #{}", bundle.getBundleId(), e); + LOGGER.error("Can't undeploy bundle #{0}", bundle.getBundleId(), e); } catch (NoSuchApplicationException e) { - LOGGER.error("Can't undeploy non existing bundle #{}", bundle.getBundleId(), e); + LOGGER.error("Can't undeploy non existing bundle #{0}", bundle.getBundleId(), e); } } - LOGGER.info("[Deployer] Bundle {} has been stopped", bundle.getSymbolicName()); + LOGGER.info("[Deployer] Bundle {0} has been stopped", bundle.getSymbolicName()); } /** @@ -230,42 +231,42 @@ public class Deployer implements BundleL * @param bundle the deployed bundle * @param appContext the appcontext to search EJBs */ - private void registerService(Bundle bundle, AppContext appContext) { + private void registerService(final Bundle bundle, final AppContext appContext) { LOGGER.info("Registering remote EJBs as OSGi services"); final BundleContext context = bundle.getBundleContext(); - for (BeanContext beanContext : appContext.getBeanContexts()) { + for (final BeanContext beanContext : appContext.getBeanContexts()) { if (beanContext.getBeanClass().equals(BeanContext.Comp.class) || BeanType.STATEFUL.equals(beanContext.getComponentType())) { continue; } try { if (beanContext.getBusinessRemoteInterface() != null) { - LOGGER.info("registering remote bean: {}", beanContext.getEjbName()); + LOGGER.info("registering remote bean: {0}", beanContext.getEjbName()); registerService(beanContext, context, beanContext.getBusinessRemoteInterfaces()); } if (beanContext.getBusinessLocalInterface() != null) { - LOGGER.info("registering local bean: {}", beanContext.getEjbName()); + LOGGER.info("registering local bean: {0}", beanContext.getEjbName()); registerService(beanContext, context, beanContext.getBusinessLocalInterfaces()); } if (beanContext.isLocalbean()) { - LOGGER.info("registering local view bean: {}", beanContext.getEjbName()); + LOGGER.info("registering local view bean: {0}", beanContext.getEjbName()); registerService(beanContext, context, Arrays.asList(beanContext.getBusinessLocalBeanInterface())); } } catch (Exception e) { - LOGGER.error("[Deployer] can't register: {}", beanContext.getEjbName()); + LOGGER.error("[Deployer] can't register: {0}", beanContext.getEjbName()); } } } - private void registerService(BeanContext beanContext, BundleContext context, List interfaces) { + private void registerService(final BeanContext beanContext, final BundleContext context, final List interfaces) { if (!interfaces.isEmpty()) { final Class[] itfs = interfaces.toArray(new Class[interfaces.size()]); try { final Object service = ProxyEJB.proxy(beanContext, itfs); registrations.get(context.getBundle()).add(context.registerService(str(itfs), service, new Properties())); - LOGGER.info("EJB registered: {} for interfaces {}", beanContext.getEjbName(), interfaces); + LOGGER.info("EJB registered: {0} for interfaces {1}", beanContext.getEjbName(), interfaces); } catch (IllegalArgumentException iae) { - LOGGER.error("can't register: {} for interfaces {}", beanContext.getEjbName(), interfaces); + LOGGER.error("can't register: {0} for interfaces {1}", beanContext.getEjbName(), interfaces); } } } @@ -274,8 +275,8 @@ public class Deployer implements BundleL return paths.keySet(); } - private static String[] str(Class[] itfs) { - String[] itfsStr = new String[itfs.length]; + private static String[] str(final Class[] itfs) { + final String[] itfsStr = new String[itfs.length]; for (int i = 0; i < itfs.length; i++) { itfsStr[i] = itfs[i].getName(); } @@ -290,13 +291,14 @@ public class Deployer implements BundleL private final Bundle backingBundle; private final Bundle fallbackBundle; - public OSGIClassLoader(Bundle bundle, Bundle openejbClassloader) { + public OSGIClassLoader(final Bundle bundle, final Bundle openejbClassloader) { super(null); backingBundle = bundle; fallbackBundle = openejbClassloader; } - protected Class findClass(String name) throws ClassNotFoundException { + @Override + protected Class findClass(final String name) throws ClassNotFoundException { try { return fallbackBundle.loadClass(name); } catch (Exception ignored) { @@ -308,13 +310,14 @@ public class Deployer implements BundleL } catch (ClassNotFoundException cnfe) { throw new ClassNotFoundException(name + " not found from bundle [" + backingBundle.getSymbolicName() + "]", cnfe); } catch (NoClassDefFoundError ncdfe) { - NoClassDefFoundError e = new NoClassDefFoundError(name + " not found from bundle [" + backingBundle + "]"); + final NoClassDefFoundError e = new NoClassDefFoundError(name + " not found from bundle [" + backingBundle + "]"); e.initCause(ncdfe); throw e; } } - protected URL findResource(String name) { + @Override + protected URL findResource(final String name) { URL url = fallbackBundle.getResource(name); if (url != null) { return url; @@ -326,11 +329,13 @@ public class Deployer implements BundleL return null; } - public Enumeration getResources(String name) throws IOException { + @Override + public Enumeration getResources(final String name) throws IOException { return findResources(name); } - protected Enumeration findResources(String name) throws IOException { + @Override + protected Enumeration findResources(final String name) throws IOException { Enumeration urls; try { urls = fallbackBundle.getResources(name); @@ -350,12 +355,14 @@ public class Deployer implements BundleL return new EmptyEnumeration(); } - public URL getResource(String name) { + @Override + public URL getResource(final String name) { return findResource(name); } - protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - Class clazz = findClass(name); + @Override + protected Class loadClass(final String name, final boolean resolve) throws ClassNotFoundException { + final Class clazz = findClass(name); if (resolve) { resolveClass(clazz); } @@ -382,18 +389,19 @@ public class Deployer implements BundleL public class OSGiDeploymentLoader extends DeploymentLoader { private final Bundle bundle; - public OSGiDeploymentLoader(Bundle bdl) { + public OSGiDeploymentLoader(final Bundle bdl) { bundle = bdl; } - @Override protected ClassLoader getOpenEJBClassLoader(URL url) { + @Override + protected ClassLoader getOpenEJBClassLoader(final URL url) { return new OSGIClassLoader(bundle, OpenEJBBundleContextHolder.get().getBundle()); } } - private static Class forceLoadClass(String name) { + private static Class forceLoadClass(final String name) { final Bundle[] bundles = OpenEJBBundleContextHolder.get().getBundles(); - for (Bundle bundle : bundles) { + for (final Bundle bundle : bundles) { try { return bundle.loadClass(name); } catch (ClassNotFoundException e) { @@ -403,10 +411,10 @@ public class Deployer implements BundleL return null; } - private static URL forceLoadResource(String name) { + private static URL forceLoadResource(final String name) { final Bundle[] bundles = OpenEJBBundleContextHolder.get().getBundles(); - for (Bundle bundle : bundles) { - URL url = bundle.getResource(name); + for (final Bundle bundle : bundles) { + final URL url = bundle.getResource(name); if (url != null) { return url; } @@ -414,9 +422,9 @@ public class Deployer implements BundleL return null; } - private static Enumeration forceLoadResources(String name) { + private static Enumeration forceLoadResources(final String name) { final Bundle[] bundles = OpenEJBBundleContextHolder.get().getBundles(); - for (Bundle bundle : bundles) { + for (final Bundle bundle : bundles) { Enumeration url = null; try { url = bundle.getResources(name); Modified: openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java (original) +++ openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/RegisterOSGIServicesExtension.java Fri Feb 24 16:13:44 2012 @@ -50,7 +50,7 @@ public class RegisterOSGIServicesExtensi for (ServiceReference service : services) { final Class clazz = serviceClass(service); abd.addBean(new OSGiServiceBean(service)); - LOGGER.debug("added service {} as a CDI Application scoped bean", clazz.getName()); + LOGGER.debug("added service {0} as a CDI Application scoped bean", clazz.getName()); } } } Modified: openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java (original) +++ openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/SocketConnectionFactory.java Fri Feb 24 16:13:44 2012 @@ -39,51 +39,61 @@ import java.util.concurrent.locks.Reentr public class SocketConnectionFactory implements ConnectionFactory { private KeepAliveStyle keepAliveStyle = KeepAliveStyle.PING; - - public static final String PROPERTY_POOL_TIMEOUT = "openejb.client.connection.pool.timeout"; - private static final String PROPERTY_POOL_TIMEOUT2 = "openejb.client.connectionpool.timeout"; - public static final String PROPERTY_POOL_SIZE = "openejb.client.connection.pool.size"; - private static final String PROPERTY_POOL_SIZE2 = "openejb.client.connectionpool.size"; - public static final String PROPERTY_KEEPALIVE = "openejb.client.keepalive"; - private static Map connections = new ConcurrentHashMap(); + public static final String PROPERTY_POOL_TIMEOUT = "openejb.client.connection.pool.timeout"; + private static final String PROPERTY_POOL_TIMEOUT2 = "openejb.client.connectionpool.timeout"; + public static final String PROPERTY_POOL_SIZE = "openejb.client.connection.pool.size"; + private static final String PROPERTY_POOL_SIZE2 = "openejb.client.connectionpool.size"; + public static final String PROPERTY_KEEPALIVE = "openejb.client.keepalive"; + + private static final Map connections = new ConcurrentHashMap(); private int size = 5; private long timeout = 1000; public SocketConnectionFactory() { - size = getSize(); - timeout = getTimeout(); + this.size = getSize(); + this.timeout = getTimeout(); + + try { + String property = System.getProperty(PROPERTY_KEEPALIVE); + if (property != null) { + property = property.toUpperCase(); + this.keepAliveStyle = KeepAliveStyle.valueOf(property); + } + } catch (Throwable e) { + //Ignore + } } private long getTimeout() { - Properties p = System.getProperties(); + final Properties p = System.getProperties(); long timeout = getLong(p, SocketConnectionFactory.PROPERTY_POOL_TIMEOUT, this.timeout); timeout = getLong(p, SocketConnectionFactory.PROPERTY_POOL_TIMEOUT2, timeout); return timeout; } private int getSize() { - Properties p = System.getProperties(); + final Properties p = System.getProperties(); int size = getInt(p, SocketConnectionFactory.PROPERTY_POOL_SIZE, this.size); size = getInt(p, SocketConnectionFactory.PROPERTY_POOL_SIZE2, size); return size; } - public static int getInt(Properties p, String property, int defaultValue) { + public static int getInt(final Properties p, final String property, final int defaultValue) { final String value = p.getProperty(property); try { if (value != null) { - return Integer.parseInt(value); - } + return Integer.parseInt(value); + } } catch (NumberFormatException e) { //Ignore } - return defaultValue; + return defaultValue; } - public static long getLong(Properties p, String property, long defaultValue) { - String value = p.getProperty(property); + public static long getLong(final Properties p, final String property, final long defaultValue) { + final String value = p.getProperty(property); try { if (value != null) return Long.parseLong(value); else return defaultValue; @@ -92,9 +102,10 @@ public class SocketConnectionFactory imp } } - public Connection getConnection(URI uri) throws java.io.IOException { + @Override + public Connection getConnection(final URI uri) throws java.io.IOException { - Pool pool = getPool(uri); + final Pool pool = getPool(uri); SocketConnection conn = pool.get(); if (conn == null) { @@ -115,25 +126,25 @@ public class SocketConnectionFactory imp throw new IOException("Connection busy"); } - OutputStream ouputStream = conn.getOuputStream(); + final OutputStream ouputStream = conn.getOuputStream(); if (conn.socket.isClosed()) { pool.put(null); return getConnection(uri); } try { - ouputStream.write(getKeepAliveStyle().ordinal()); + ouputStream.write(this.keepAliveStyle.ordinal()); + ouputStream.flush(); - switch (getKeepAliveStyle()) { + switch (this.keepAliveStyle) { case PING_PING: { + ouputStream.write(this.keepAliveStyle.ordinal()); ouputStream.flush(); - ouputStream.write(getKeepAliveStyle().ordinal()); - ouputStream.flush(); + break; } - break; case PING_PONG: { - ouputStream.flush(); conn.getInputStream().read(); + break; } } } catch (IOException e) { @@ -144,7 +155,7 @@ public class SocketConnectionFactory imp return conn; } - private Pool getPool(URI uri) { + private Pool getPool(final URI uri) { Pool pool = connections.get(uri); if (pool == null) { pool = new Pool(uri, getSize(), getTimeout()); @@ -153,15 +164,6 @@ public class SocketConnectionFactory imp return pool; } - public KeepAliveStyle getKeepAliveStyle() { - String property = System.getProperty(PROPERTY_KEEPALIVE); - if (property != null) { - property = property.toUpperCase(); - return KeepAliveStyle.valueOf(property); - } - return keepAliveStyle; - } - class SocketConnection implements Connection { private Socket socket = null; @@ -173,19 +175,19 @@ public class SocketConnectionFactory imp private OutputStream out; private BufferedInputStream in; - public SocketConnection(URI uri, Pool pool) { + public SocketConnection(final URI uri, final Pool pool) { this.uri = uri; this.pool = pool; } - protected void open(URI uri) throws IOException { + protected void open(final URI uri) throws IOException { /*-----------------------*/ /* Open socket to server */ /*-----------------------*/ try { if (uri.getScheme().equalsIgnoreCase("ejbds")) { - SSLSocket sslSocket = (SSLSocket) SSLSocketFactory.getDefault().createSocket(uri.getHost(), uri.getPort()); + final SSLSocket sslSocket = (SSLSocket) SSLSocketFactory.getDefault().createSocket(uri.getHost(), uri.getPort()); // use an anonymous cipher suite so that a KeyManager or // TrustManager is not needed // NOTE: this assumes that the cipher suite is known. A check @@ -199,35 +201,39 @@ public class SocketConnectionFactory imp socket.setTcpNoDelay(true); } catch (ConnectException e) { - throw new ConnectException("Cannot connect to server '" + uri.toString() + "'. Check that the server is started and that the specified serverURL is correct."); + throw new IOException("Cannot connect to server '" + uri.toString() + "'. Check that the server is started and that the specified serverURL is correct.", e); } catch (IOException e) { - throw new IOException("Cannot connect to server: '" + uri.toString() + "'. Exception: " + e.getClass().getName() + " : " + e.getMessage()); + throw new IOException("Cannot connect to server: '" + uri.toString() + "'. Exception: " + e.getClass().getName() + " : " + e.getMessage(), e); } catch (SecurityException e) { - throw new IOException("Cannot access server: '" + uri.toString() + "' due to security restrictions in the current VM: " + e.getClass().getName() + " : " + e.getMessage()); + throw new IOException("Cannot access server: '" + uri.toString() + "' due to security restrictions in the current VM: " + e.getClass().getName() + " : " + e.getMessage(), e); } catch (Throwable e) { - throw new IOException("Cannot connect to server: '" + uri.toString() + "' due to an unkown exception in the OpenEJB client: " + e.getClass().getName() + " : " + e.getMessage()); + throw new IOException("Cannot connect to server: '" + uri.toString() + "' due to an unkown exception in the OpenEJB client: " + e.getClass().getName() + " : " + e.getMessage(), e); } } + @Override public void discard() { pool.put(null); discarded = true; try { socket.close(); - } catch (IOException e) { + } catch (Throwable e) { + //Ignore } // don't bother unlocking it // it should never get used again } + @Override public URI getURI() { return uri; } + @Override public void close() throws IOException { if (discarded) return; @@ -235,6 +241,7 @@ public class SocketConnectionFactory imp lock.unlock(); } + @Override public InputStream getInputStream() throws IOException { /*----------------------------------*/ /* Open input streams */ @@ -256,6 +263,7 @@ public class SocketConnectionFactory imp } } + @Override public OutputStream getOuputStream() throws IOException { /*----------------------------------*/ /* Openning output streams */ @@ -277,19 +285,21 @@ public class SocketConnectionFactory imp public class Input extends java.io.FilterInputStream { - public Input(InputStream in) { + public Input(final InputStream in) { super(in); } + @Override public void close() throws IOException { } } public class Output extends java.io.FilterOutputStream { - public Output(OutputStream out) { + public Output(final OutputStream out) { super(out); } + @Override public void close() throws IOException { flush(); } @@ -303,7 +313,7 @@ public class SocketConnectionFactory imp private final int size; private final URI uri; - private Pool(URI uri, int size, long timeout) { + private Pool(final URI uri, final int size, final long timeout) { this.uri = uri; this.size = size; this.semaphore = new Semaphore(size); @@ -311,13 +321,12 @@ public class SocketConnectionFactory imp this.timeout = timeout; this.timeUnit = TimeUnit.MILLISECONDS; - Object[] objects = new Object[size]; - for (int i = 0; i < objects.length; i++) { + for (int i = 0; i < size; i++) { pool.push(null); } } - public SocketConnection get() throws IOException{ + public SocketConnection get() throws IOException { try { if (semaphore.tryAcquire(timeout, timeUnit)) { return pool.pop(); @@ -329,7 +338,7 @@ public class SocketConnectionFactory imp throw new ConnectionPoolTimeoutException("No connections available in pool (size " + size + "). Waited for " + timeout + " milliseconds for a connection."); } - public void put(SocketConnection connection) { + public void put(final SocketConnection connection) { pool.push(connection); semaphore.release(); } Modified: openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java (original) +++ openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java Fri Feb 24 16:13:44 2012 @@ -44,9 +44,9 @@ class EjbRequestHandler { private final ClusterableRequestHandler clusterableRequestHandler; - private Map asynchronousInvocationCancelMap = new ConcurrentHashMap(); + private final Map asynchronousInvocationCancelMap = new ConcurrentHashMap(); - EjbRequestHandler(EjbDaemon daemon) { + EjbRequestHandler(final EjbDaemon daemon) { this.daemon = daemon; clusterableRequestHandler = newClusterableRequestHandler(); @@ -56,14 +56,14 @@ class EjbRequestHandler { return new BasicClusterableRequestHandler(); } - public void processRequest(ObjectInputStream in, ObjectOutputStream out) { + public void processRequest(final ObjectInputStream in, final ObjectOutputStream out) { // Setup the client proxy replacement to replace // the proxies with the IntraVM proxy implementations EJBHomeProxyHandle.resolver.set(SERVER_SIDE_RESOLVER); EJBObjectProxyHandle.resolver.set(SERVER_SIDE_RESOLVER); - EJBRequest req = new EJBRequest(); - EJBResponse res = new EJBResponse(); + final EJBRequest req = new EJBRequest(); + final EJBResponse res = new EJBResponse(); try { req.readExternal(in); @@ -72,9 +72,9 @@ class EjbRequestHandler { return; } - SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class); + final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class); try { - Object clientIdentity = req.getClientIdentity(); + final Object clientIdentity = req.getClientIdentity(); if (clientIdentity != null) securityService.associate(clientIdentity); } catch (Throwable t) { replyWithFatalError(out, t, "Client identity is not valid"); @@ -101,7 +101,7 @@ class EjbRequestHandler { } // Need to set this for deserialization of the body - ClassLoader classLoader = di.getBeanClass().getClassLoader(); + final ClassLoader classLoader = di.getBeanClass().getClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); try { @@ -238,14 +238,14 @@ class EjbRequestHandler { } } - protected void updateServer(EJBRequest req, EJBResponse res) { - CallContext callContext = CallContext.getCallContext(); - BeanContext beanContext = callContext.getBeanContext(); + protected void updateServer(final EJBRequest req, final EJBResponse res) { + final CallContext callContext = CallContext.getCallContext(); + final BeanContext beanContext = callContext.getBeanContext(); clusterableRequestHandler.updateServer(beanContext, req, res); } - protected void doFUTURE_CANCEL_METHOD(EJBRequest req, EJBResponse res) throws Exception { - AtomicBoolean invocationCancelTag = asynchronousInvocationCancelMap.get(req.getBody().getRequestId()); + protected void doFUTURE_CANCEL_METHOD(final EJBRequest req, final EJBResponse res) throws Exception { + final AtomicBoolean invocationCancelTag = asynchronousInvocationCancelMap.get(req.getBody().getRequestId()); if (invocationCancelTag == null) { //TODO ? } else { @@ -254,18 +254,18 @@ class EjbRequestHandler { } } - protected void doEjbObject_BUSINESS_METHOD(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbObject_BUSINESS_METHOD(final EJBRequest req, final EJBResponse res) throws Exception { - CallContext call = CallContext.getCallContext(); - BeanContext beanContext = (BeanContext) call.getBeanContext(); - boolean asynchronous = beanContext.isAsynchronous(req.getMethodInstance()); + final CallContext call = CallContext.getCallContext(); + final BeanContext beanContext = (BeanContext) call.getBeanContext(); + final boolean asynchronous = beanContext.isAsynchronous(req.getMethodInstance()); try { if (asynchronous) { - AtomicBoolean invocationCancelTag = new AtomicBoolean(false); + final AtomicBoolean invocationCancelTag = new AtomicBoolean(false); ThreadContext.initAsynchronousCancelled(invocationCancelTag); asynchronousInvocationCancelMap.put(req.getBody().getRequestId(), invocationCancelTag); } - RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); + final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); Object result = c.invoke(req.getDeploymentId(), req.getInterfaceClass(), req.getMethodInstance(), @@ -287,12 +287,12 @@ class EjbRequestHandler { } } - protected void doEjbHome_METHOD(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbHome_METHOD(final EJBRequest req, final EJBResponse res) throws Exception { - CallContext call = CallContext.getCallContext(); - RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); + final CallContext call = CallContext.getCallContext(); + final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); - Object result = c.invoke(req.getDeploymentId(), + final Object result = c.invoke(req.getDeploymentId(), req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey() @@ -301,10 +301,10 @@ class EjbRequestHandler { res.setResponse(ResponseCodes.EJB_OK, result); } - protected void doEjbHome_CREATE(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbHome_CREATE(final EJBRequest req, final EJBResponse res) throws Exception { - CallContext call = CallContext.getCallContext(); - RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); + final CallContext call = CallContext.getCallContext(); + final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); Object result = c.invoke(req.getDeploymentId(), req.getInterfaceClass(), req.getMethodInstance(), @@ -313,7 +313,7 @@ class EjbRequestHandler { ); if (result instanceof ProxyInfo) { - ProxyInfo info = (ProxyInfo) result; + final ProxyInfo info = (ProxyInfo) result; res.setResponse(ResponseCodes.EJB_OK, info.getPrimaryKey()); } else { @@ -323,10 +323,10 @@ class EjbRequestHandler { } } - protected void doEjbHome_FIND(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbHome_FIND(final EJBRequest req, final EJBResponse res) throws Exception { - CallContext call = CallContext.getCallContext(); - RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); + final CallContext call = CallContext.getCallContext(); + final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); Object result = c.invoke(req.getDeploymentId(), req.getInterfaceClass(), req.getMethodInstance(), @@ -337,10 +337,10 @@ class EjbRequestHandler { /* Multiple instances found */ if (result instanceof Collection) { - Object[] primaryKeys = ((Collection) result).toArray(); + final Object[] primaryKeys = ((Collection) result).toArray(); for (int i = 0; i < primaryKeys.length; i++) { - ProxyInfo proxyInfo = ((ProxyInfo) primaryKeys[i]); + final ProxyInfo proxyInfo = ((ProxyInfo) primaryKeys[i]); if (proxyInfo == null) { primaryKeys[i] = null; } else { @@ -352,10 +352,10 @@ class EjbRequestHandler { } else if (result instanceof java.util.Enumeration) { - java.util.Enumeration resultAsEnum = (java.util.Enumeration) result; - java.util.List listOfPKs = new ArrayList(); + final java.util.Enumeration resultAsEnum = (java.util.Enumeration) result; + final java.util.List listOfPKs = new ArrayList(); while (resultAsEnum.hasMoreElements()) { - ProxyInfo proxyInfo = ((ProxyInfo) resultAsEnum.nextElement()); + final ProxyInfo proxyInfo = ((ProxyInfo) resultAsEnum.nextElement()); if (proxyInfo == null) { listOfPKs.add(null); } else { @@ -366,7 +366,7 @@ class EjbRequestHandler { res.setResponse(ResponseCodes.EJB_OK_FOUND_ENUMERATION, listOfPKs.toArray(new Object[listOfPKs.size()])); /* Single instance found */ } else if (result instanceof ProxyInfo) { - ProxyInfo proxyInfo = ((ProxyInfo) result); + final ProxyInfo proxyInfo = ((ProxyInfo) result); result = proxyInfo.getPrimaryKey(); res.setResponse(ResponseCodes.EJB_OK_FOUND, result); } else if (result == null) { @@ -383,28 +383,28 @@ class EjbRequestHandler { } } - protected void doEjbObject_GET_EJB_HOME(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbObject_GET_EJB_HOME(final EJBRequest req, final EJBResponse res) throws Exception { checkMethodAuthorization(req, res); } - protected void doEjbObject_GET_HANDLE(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbObject_GET_HANDLE(final EJBRequest req, final EJBResponse res) throws Exception { checkMethodAuthorization(req, res); } - protected void doEjbObject_GET_PRIMARY_KEY(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbObject_GET_PRIMARY_KEY(final EJBRequest req, final EJBResponse res) throws Exception { checkMethodAuthorization(req, res); } - protected void doEjbObject_IS_IDENTICAL(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbObject_IS_IDENTICAL(final EJBRequest req, final EJBResponse res) throws Exception { checkMethodAuthorization(req, res); } - protected void doEjbObject_REMOVE(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbObject_REMOVE(final EJBRequest req, final EJBResponse res) throws Exception { - CallContext call = CallContext.getCallContext(); - RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); + final CallContext call = CallContext.getCallContext(); + final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); - Object result = c.invoke(req.getDeploymentId(), + final Object result = c.invoke(req.getDeploymentId(), req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey() @@ -413,20 +413,20 @@ class EjbRequestHandler { res.setResponse(ResponseCodes.EJB_OK, null); } - protected void doEjbHome_GET_EJB_META_DATA(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbHome_GET_EJB_META_DATA(final EJBRequest req, final EJBResponse res) throws Exception { checkMethodAuthorization(req, res); } - protected void doEjbHome_GET_HOME_HANDLE(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbHome_GET_HOME_HANDLE(final EJBRequest req, final EJBResponse res) throws Exception { checkMethodAuthorization(req, res); } - protected void doEjbHome_REMOVE_BY_HANDLE(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbHome_REMOVE_BY_HANDLE(final EJBRequest req, final EJBResponse res) throws Exception { - CallContext call = CallContext.getCallContext(); - RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); + final CallContext call = CallContext.getCallContext(); + final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); - Object result = c.invoke(req.getDeploymentId(), + final Object result = c.invoke(req.getDeploymentId(), req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey() @@ -435,12 +435,12 @@ class EjbRequestHandler { res.setResponse(ResponseCodes.EJB_OK, null); } - protected void doEjbHome_REMOVE_BY_PKEY(EJBRequest req, EJBResponse res) throws Exception { + protected void doEjbHome_REMOVE_BY_PKEY(final EJBRequest req, final EJBResponse res) throws Exception { - CallContext call = CallContext.getCallContext(); - RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); + final CallContext call = CallContext.getCallContext(); + final RpcContainer c = (RpcContainer) call.getBeanContext().getContainer(); - Object result = c.invoke(req.getDeploymentId(), + final Object result = c.invoke(req.getDeploymentId(), req.getInterfaceClass(), req.getMethodInstance(), req.getMethodParameters(), req.getPrimaryKey() @@ -449,11 +449,11 @@ class EjbRequestHandler { res.setResponse(ResponseCodes.EJB_OK, null); } - protected void checkMethodAuthorization(EJBRequest req, EJBResponse res) throws Exception { + protected void checkMethodAuthorization(final EJBRequest req, final EJBResponse res) throws Exception { res.setResponse(ResponseCodes.EJB_OK, null); } - private void replyWithFatalError(ObjectOutputStream out, Throwable error, String message) { + private void replyWithFatalError(final ObjectOutputStream out, final Throwable error, final String message) { //This is fatal for the client, but not the server. if (logger.isWarningEnabled()) { Modified: openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbServer.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbServer.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbServer.java (original) +++ openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbServer.java Fri Feb 24 16:13:44 2012 @@ -16,21 +16,20 @@ */ package org.apache.openejb.server.ejbd; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.Socket; -import java.util.Properties; - -import org.apache.openejb.server.ServiceException; -import org.apache.openejb.core.ServerFederation; import org.apache.openejb.ProxyInfo; +import org.apache.openejb.core.ServerFederation; +import org.apache.openejb.server.ServiceException; +import javax.ejb.EJBHome; import javax.ejb.EJBMetaData; +import javax.ejb.EJBObject; import javax.ejb.Handle; import javax.ejb.HomeHandle; -import javax.ejb.EJBObject; -import javax.ejb.EJBHome; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.util.Properties; public class EjbServer implements org.apache.openejb.server.ServerService, org.apache.openejb.spi.ApplicationServer { @@ -41,32 +40,39 @@ public class EjbServer implements org.ap keepAlive = new KeepAliveServer(this); } - public void init(Properties props) throws Exception { + @Override + public void init(final Properties props) throws Exception { server = EjbDaemon.getEjbDaemon(); server.init(props); } + @Override public void start() throws ServiceException { keepAlive.start(); } + @Override public void stop() throws ServiceException { keepAlive.stop(); } + @Override public String getName() { return "ejbd"; } + @Override public int getPort() { return 0; } - public void service(Socket socket) throws ServiceException, IOException { + @Override + public void service(final Socket socket) throws ServiceException, IOException { keepAlive.service(socket); } - public void service(InputStream inputStream, OutputStream outputStream) throws ServiceException, IOException { + @Override + public void service(final InputStream inputStream, final OutputStream outputStream) throws ServiceException, IOException { ServerFederation.setApplicationServer(server); final ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); @@ -77,31 +83,38 @@ public class EjbServer implements org.ap } } + @Override public String getIP() { return ""; } - public EJBMetaData getEJBMetaData(ProxyInfo info) { + @Override + public EJBMetaData getEJBMetaData(final ProxyInfo info) { return server.getEJBMetaData(info); } - public Handle getHandle(ProxyInfo info) { + @Override + public Handle getHandle(final ProxyInfo info) { return server.getHandle(info); } - public HomeHandle getHomeHandle(ProxyInfo info) { + @Override + public HomeHandle getHomeHandle(final ProxyInfo info) { return server.getHomeHandle(info); } - public EJBObject getEJBObject(ProxyInfo info) { + @Override + public EJBObject getEJBObject(final ProxyInfo info) { return server.getEJBObject(info); } - public Object getBusinessObject(ProxyInfo info) { - return server.getBusinessObject(info); + @Override + public Object getBusinessObject(final ProxyInfo info) { + return server.getBusinessObject(info); } - public EJBHome getEJBHome(ProxyInfo info) { + @Override + public EJBHome getEJBHome(final ProxyInfo info) { return server.getEJBHome(info); } } Modified: openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java (original) +++ openejb/trunk/openejb/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/KeepAliveServer.java Fri Feb 24 16:13:44 2012 @@ -51,7 +51,7 @@ public class KeepAliveServer implements private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SERVER.createChild("keepalive"), KeepAliveServer.class); private final ServerService service; - private final long timeout = (1000 * 3); + private final long timeout = (1000 * 10); private final AtomicBoolean running = new AtomicBoolean(false); private final ConcurrentHashMap sessions = new ConcurrentHashMap(); @@ -68,7 +68,9 @@ public class KeepAliveServer implements private void closeInactiveSessions() { - if (!this.running.get()) return; + if (!this.running.get()) { + return; + } final BlockingQueue queue = getQueue(); if (queue == null) return; @@ -83,24 +85,24 @@ public class KeepAliveServer implements for (final Session session : current) { - if (session.usage.tryLock()) { + final Lock l = session.usage; + + if (l.tryLock()) { try { if (now - session.lastRequest > timeout) { + + backlog--; + try { - backlog--; session.socket.close(); - } catch (IOException e) { - if (logger.isWarningEnabled()) { - logger.warning("closeInactiveSessions: Error closing socket. Debug for StackTrace"); - } else if (logger.isDebugEnabled()) { - logger.debug("closeInactiveSessions: Error closing socket.", e); - } + } catch (Throwable e) { + //Ignore } finally { removeSession(session); } } } finally { - session.usage.unlock(); + l.unlock(); } } @@ -115,23 +117,24 @@ public class KeepAliveServer implements current.addAll(this.sessions.values()); for (final Session session : current) { - if (session.usage.tryLock()) { + + final Lock l = session.usage; + + if (l.tryLock()) { try { session.socket.close(); - } catch (IOException e) { - if (logger.isWarningEnabled()) { - logger.warning("closeSessions: Error closing socket. Debug for StackTrace"); - } else if (logger.isDebugEnabled()) { - logger.debug("closeSessions: Error closing socket.", e); - } + } catch (Throwable e) { + //Ignore } finally { removeSession(session); - session.usage.unlock(); + l.unlock(); } } else if (logger.isDebugEnabled()) { logger.debug("Allowing graceful shutdown of " + session.socket.getInetAddress()); } } + + this.sessions.clear(); } private BlockingQueue getQueue() { @@ -179,14 +182,14 @@ public class KeepAliveServer implements // only used inside the Lock private final Socket socket; - public Session(final KeepAliveServer kas, final Socket socket) { + protected Session(final KeepAliveServer kas, final Socket socket) { this.kas = kas; this.socket = socket; this.lastRequest = System.currentTimeMillis(); this.thread = Thread.currentThread(); } - public void service(final Socket socket) throws ServiceException, IOException { + protected void service(final Socket socket) throws ServiceException, IOException { this.kas.addSession(this); int i = -1; @@ -208,15 +211,15 @@ public class KeepAliveServer implements } final KeepAliveStyle style = KeepAliveStyle.values()[i]; + final Lock l = this.usage; try { - usage.lock(); + l.lock(); switch (style) { case PING_PING: { - in.read(); + i = in.read(); break; } - case PING_PONG: { out.write(style.ordinal()); out.flush(); @@ -224,11 +227,16 @@ public class KeepAliveServer implements } } - service.service(new Input(in), new Output(out)); - out.flush(); + try { + service.service(new Input(in), new Output(out)); + out.flush(); + } catch (SocketException e) { + // Socket closed. + break; + } } finally { this.lastRequest = System.currentTimeMillis(); - usage.unlock(); + l.unlock(); } } } catch (ArrayIndexOutOfBoundsException e) { @@ -241,7 +249,6 @@ public class KeepAliveServer implements } } - @Override public void service(final Socket socket) throws ServiceException, IOException { final Session session = new Session(this, socket); @@ -283,7 +290,11 @@ public class KeepAliveServer implements } catch (Throwable e) { //Ignore } - this.timer.cancel(); + try { + this.timer.cancel(); + } catch (Throwable e) { + //Ignore + } } } Modified: openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/Server.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/Server.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/Server.java (original) +++ openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/Server.java Fri Feb 24 16:13:44 2012 @@ -52,11 +52,11 @@ public class Server implements Service { // TODO: Remove it once init() suits our (initialisation) needs @Override - public void init(Properties props) throws Exception { + public void init(final Properties props) throws Exception { this.props = props; - SystemInstance system = SystemInstance.get(); - File home = system.getHome().getDirectory(); + final SystemInstance system = SystemInstance.get(); + final File home = system.getHome().getDirectory(); system.setProperty(DeploymentFilterable.CLASSPATH_INCLUDE, system.getProperty(DeploymentFilterable.CLASSPATH_INCLUDE, ".*/" + home.getName() + "/lib/.*")); system.setProperty(DeploymentFilterable.CLASSPATH_REQUIRE_DESCRIPTOR, system.getProperty(DeploymentFilterable.CLASSPATH_REQUIRE_DESCRIPTOR, "true")); system.setProperty(DeploymentFilterable.CLASSPATH_FILTER_SYSTEMAPPS, system.getProperty(DeploymentFilterable.CLASSPATH_FILTER_SYSTEMAPPS, "false")); @@ -99,21 +99,21 @@ public class Server implements Service { manager.stop(); } - public void addService(URI uri) { + public void addService(final URI uri) { } public static class ServerServiceFactory { - public ServerService createService(URI location) throws IOException { + public ServerService createService(final URI location) throws IOException { return null; } } - public void setServiceManager(ServiceManager serviceManager) { + public void setServiceManager(final ServiceManager serviceManager) { manager = serviceManager; } - public void setPropertiesService(PropertiesService propertiesService) { + public void setPropertiesService(final PropertiesService propertiesService) { this.propertiesService = propertiesService; } } Modified: openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java?rev=1293319&r1=1293318&r2=1293319&view=diff ============================================================================== --- openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java (original) +++ openejb/trunk/openejb/server/openejb-server/src/main/java/org/apache/openejb/server/ServicePool.java Fri Feb 24 16:13:44 2012 @@ -16,23 +16,22 @@ */ package org.apache.openejb.server; -import java.util.concurrent.Executor; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.openejb.util.LogCategory; -import org.apache.openejb.util.Logger; import org.apache.openejb.loader.Options; import org.apache.openejb.loader.SystemInstance; +import org.apache.openejb.util.LogCategory; +import org.apache.openejb.util.Logger; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.util.Properties; +import java.util.concurrent.Executor; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; public class ServicePool implements ServerService { private static final Logger log = Logger.getInstance(LogCategory.SERVICEPOOL, "org.apache.openejb.util.resources"); @@ -42,22 +41,22 @@ public class ServicePool implements Serv private final ThreadPoolExecutor threadPool; private final AtomicBoolean stop = new AtomicBoolean(); - public ServicePool(ServerService next, String name, Properties properties) { + public ServicePool(final ServerService next, final String name, final Properties properties) { this(next, name, new Options(properties).get("threads", 100)); } - public ServicePool(ServerService next, final String name, int threads) { + public ServicePool(final ServerService next, final String name, final int threads) { this.next = next; final int keepAliveTime = (1000 * 60 * 5); - threadPool = new ThreadPoolExecutor(threads, threads, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); + threadPool = new ThreadPoolExecutor(threads, threads, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); threadPool.setThreadFactory(new ThreadFactory() { private volatile int id = 0; - public Thread newThread(Runnable arg0) { - Thread thread = new Thread(arg0, name + " " + getNextID()); - return thread; + @Override + public Thread newThread(final Runnable arg0) { + return new Thread(arg0, name + " " + getNextID()); } private int getNextID() { @@ -70,7 +69,7 @@ public class ServicePool implements Serv SystemInstance.get().setComponent(ServicePool.class, this); } - public ServicePool(ServerService next, Executor executor) { + public ServicePool(final ServerService next, final Executor executor) { this.next = next; this.executor = executor; this.threadPool = null; @@ -80,17 +79,22 @@ public class ServicePool implements Serv return threadPool; } - public void service(InputStream in, OutputStream out) throws ServiceException, IOException { + @Override + public void service(final InputStream in, final OutputStream out) throws ServiceException, IOException { } + @Override public void service(final Socket socket) throws ServiceException, IOException { final Runnable service = new Runnable() { + @Override public void run() { try { if (stop.get()) return; next.service(socket); } catch (SecurityException e) { log.error("Security error: " + e.getMessage(), e); + } catch (IOException e) { + log.debug("Unexpected IO error", e); } catch (Throwable e) { log.error("Unexpected error", e); } finally { @@ -112,9 +116,10 @@ public class ServicePool implements Serv }; final ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - Runnable ctxCL = new Runnable() { + final Runnable ctxCL = new Runnable() { + @Override public void run() { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); + final ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(tccl); try { service.run(); @@ -130,16 +135,18 @@ public class ServicePool implements Serv /** * Pulls out the access log information * - * @param props + * @param props Properties * @throws ServiceException */ - public void init(Properties props) throws Exception { + @Override + public void init(final Properties props) throws Exception { // Do our stuff // Then call the next guy next.init(props); } + @Override public void start() throws ServiceException { // Do our stuff @@ -147,6 +154,7 @@ public class ServicePool implements Serv next.start(); } + @Override public void stop() throws ServiceException { // Do our stuff @@ -159,6 +167,7 @@ public class ServicePool implements Serv * Gets the name of the service. * Used for display purposes only */ + @Override public String getName() { return next.getName(); } @@ -167,6 +176,7 @@ public class ServicePool implements Serv * Gets the ip number that the * daemon is listening on. */ + @Override public String getIP() { return next.getIP(); } @@ -175,6 +185,7 @@ public class ServicePool implements Serv * Gets the port number that the * daemon is listening on. */ + @Override public int getPort() { return next.getPort(); }