Browse files

TAP5-1539: Update a few places to use Runnable not (deprecated) Regis…

…tryShutdownListener

git-svn-id: https://svn.apache.org/repos/asf/tapestry/tapestry5/trunk@1183527 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 76db8d0 commit 940f50bcb17bca34e8b3658e5e21eee3ab4ab79b @hlship hlship committed Oct 14, 2011
View
11 ...stry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateCoreModule.java
@@ -45,6 +45,7 @@ public static void bind(ServiceBinder binder)
binder.bind(HibernateTransactionDecorator.class, HibernateTransactionDecoratorImpl.class);
binder.bind(HibernateTransactionAdvisor.class, HibernateTransactionAdvisorImpl.class);
binder.bind(HibernateConfigurer.class, DefaultHibernateConfigurer.class).withSimpleId();
+ binder.bind(HibernateSessionSource.class, HibernateSessionSourceImpl.class);
}
@@ -117,16 +118,6 @@ public static Session buildSession(HibernateSessionManager sessionManager,
return propertyShadowBuilder.build(sessionManager, "session", Session.class);
}
- public static HibernateSessionSource buildHibernateSessionSource(Logger logger, List<HibernateConfigurer> config,
- RegistryShutdownHub hub)
- {
- HibernateSessionSourceImpl hss = new HibernateSessionSourceImpl(logger, config);
-
- hub.addRegistryShutdownListener(hss);
-
- return hss;
- }
-
/**
* Adds the following configurers: <dl> <dt>Default <dd> performs default hibernate configuration <dt>PackageName
* <dd> loads entities by package name</dl>
View
27 ...ore/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImpl.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,18 +14,19 @@
package org.apache.tapestry5.internal.hibernate;
-import java.util.List;
-
import org.apache.tapestry5.hibernate.HibernateConfigurer;
import org.apache.tapestry5.hibernate.HibernateSessionSource;
-import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
+import org.apache.tapestry5.ioc.annotations.PostInjection;
+import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.slf4j.Logger;
-public class HibernateSessionSourceImpl implements HibernateSessionSource, RegistryShutdownListener
+import java.util.List;
+
+public class HibernateSessionSourceImpl implements HibernateSessionSource
{
private final SessionFactory sessionFactory;
@@ -51,6 +52,18 @@ public HibernateSessionSourceImpl(Logger logger, List<HibernateConfigurer> hiber
logger.info(HibernateCoreMessages.entityCatalog(sessionFactory.getAllClassMetadata().keySet()));
}
+ @PostInjection
+ public void listenForShutdown(RegistryShutdownHub hub)
+ {
+ hub.addRegistryShutdownListener(new Runnable()
+ {
+ public void run()
+ {
+ sessionFactory.close();
+ }
+ });
+ }
+
public Session create()
{
return sessionFactory.openSession();
@@ -66,8 +79,4 @@ public Configuration getConfiguration()
return configuration;
}
- public void registryDidShutdown()
- {
- sessionFactory.close();
- }
}
View
4 tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
@@ -145,9 +145,9 @@ public RegistryImpl(Collection<ModuleDef> moduleDefs, ClassFactory classFactory,
lifecycles.put("singleton", new SingletonServiceLifecycle());
- registryShutdownHub.addRegistryShutdownListener(new RegistryShutdownListener()
+ registryShutdownHub.addRegistryShutdownListener(new Runnable()
{
- public void registryDidShutdown()
+ public void run()
{
scoreboardAndTracker.shutdown();
}
View
15 ...ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreator.java
@@ -17,7 +17,6 @@
import org.apache.tapestry5.ioc.ObjectCreator;
import org.apache.tapestry5.ioc.internal.EagerLoadServiceProxy;
import org.apache.tapestry5.ioc.internal.ServiceActivityTracker;
-import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.apache.tapestry5.ioc.services.Status;
/**
@@ -26,7 +25,7 @@
* same time (a service should be realized only once). The additional interfaces implemented by this class support eager
* loading of services (at application startup), and orderly shutdown of proxies.
*/
-public class JustInTimeObjectCreator<T> implements ObjectCreator<T>, EagerLoadServiceProxy, RegistryShutdownListener
+public class JustInTimeObjectCreator<T> implements ObjectCreator<T>, EagerLoadServiceProxy, Runnable
{
private final ServiceActivityTracker tracker;
@@ -46,9 +45,8 @@ public JustInTimeObjectCreator(ServiceActivityTracker tracker, ObjectCreator<T>
/**
* Checks to see if the proxy has been shutdown, then invokes {@link ObjectCreator#createObject()} if it has not
* already done so.
- *
- * @throws IllegalStateException
- * if the registry has been shutdown
+ *
+ * @throws IllegalStateException if the registry has been shutdown
*/
public T createObject()
{
@@ -72,8 +70,7 @@ private synchronized void obtainObjectFromCreator()
tracker.setStatus(serviceId, Status.REAL);
creator = null;
- }
- catch (RuntimeException ex)
+ } catch (RuntimeException ex)
{
throw new RuntimeException(ServiceMessages.serviceBuildFailure(serviceId, ex), ex);
}
@@ -90,9 +87,9 @@ public void eagerLoadService()
}
/**
- * Sets the shutdown flag and releases the object and the creator.
+ * Invoked when the Registry is shutdown; sets the shutdown flag and releases the object and the creator.
*/
- public void registryDidShutdown()
+ public void run()
{
creator = new ObjectCreator<T>()
{
View
2 ...c/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
@@ -277,7 +277,7 @@ private synchronized boolean isShutdown()
return shutdown;
}
- public synchronized void registryDidShutdown()
+ private synchronized void registryDidShutdown()
{
shutdown = true;
View
4 tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
@@ -508,9 +508,9 @@ public static ParallelExecutor buildDeferredExecution(@Symbol(IOCSymbols.THREAD_
final ThreadPoolExecutor executorService = new ThreadPoolExecutor(coreSize, maxSize, keepAliveMillis,
TimeUnit.MILLISECONDS, workQueue);
- shutdownHub.addRegistryShutdownListener(new RegistryShutdownListener()
+ shutdownHub.addRegistryShutdownListener(new Runnable()
{
- public void registryDidShutdown()
+ public void run()
{
executorService.shutdown();
}
View
4 ...src/test/java/org/apache/tapestry5/ioc/internal/services/JustInTimeObjectCreatorTest.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2009 The Apache Software Foundation
+// Copyright 2007, 2009, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ public void create_after_shutdown()
JustInTimeObjectCreator j = new JustInTimeObjectCreator(null, creator, SERVICE_ID);
- j.registryDidShutdown();
+ j.run();
try
{
View
41 tapestry-jmx/src/main/java/org/apache/tapestry5/internal/jmx/MBeanSupportImpl.java
@@ -14,25 +14,23 @@
package org.apache.tapestry5.internal.jmx;
-import static java.lang.String.format;
-
-import java.lang.management.ManagementFactory;
-import java.util.List;
-import java.util.Set;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.ObjectName;
-
import org.apache.tapestry5.ioc.annotations.PostInjection;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.OneShotLock;
import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
-import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
import org.apache.tapestry5.jmx.MBeanSupport;
import org.slf4j.Logger;
-public class MBeanSupportImpl implements MBeanSupport, RegistryShutdownListener
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+import java.util.List;
+import java.util.Set;
+
+import static java.lang.String.format;
+
+public class MBeanSupportImpl implements MBeanSupport
{
private final Logger logger;
@@ -67,7 +65,13 @@ public MBeanSupportImpl(Logger logger)
@PostInjection
public void listenForShutdown(RegistryShutdownHub hub)
{
- hub.addRegistryShutdownListener(this);
+ hub.addRegistryShutdownListener(new Runnable()
+ {
+ public void run()
+ {
+ registryDidShutdown();
+ }
+ });
}
public void register(Object bean, String name)
@@ -80,8 +84,7 @@ private static ObjectName toObjectName(String name)
try
{
return new ObjectName(name);
- }
- catch (Exception ex)
+ } catch (Exception ex)
{
throw new RuntimeException(ex);
}
@@ -101,8 +104,7 @@ public void register(final Object object, final ObjectName objectName)
this.registeredBeans.add(objectName);
this.logger.info(format("Registered MBean '%s' with server", objectName));
- }
- catch (final Exception e)
+ } catch (final Exception e)
{
this.logger.error(format("Failed to register MBean '%s' with server", objectName), e);
}
@@ -127,15 +129,14 @@ private void doUnregister(final ObjectName objectName)
if (registeredBeans.contains(objectName))
registeredBeans.remove(objectName);
- }
- catch (final Exception e)
+ } catch (final Exception e)
{
this.logger.error(String.format("Failed to unregister MBean '%s' from server", objectName), e);
}
}
}
- public void registryDidShutdown()
+ private void registryDidShutdown()
{
lock.lock();
// store into new data structure so we can remove them from registered beans
View
90 tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/EntityManagerSourceImpl.java
@@ -14,34 +14,33 @@
package org.apache.tapestry5.internal.jpa;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.spi.PersistenceProvider;
-import javax.persistence.spi.PersistenceProviderResolver;
-import javax.persistence.spi.PersistenceProviderResolverHolder;
-import javax.persistence.spi.PersistenceUnitInfo;
-
import org.apache.tapestry5.func.F;
import org.apache.tapestry5.func.Mapper;
import org.apache.tapestry5.func.Predicate;
import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.annotations.Local;
+import org.apache.tapestry5.ioc.annotations.PostInjection;
+import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
-import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
-import org.apache.tapestry5.jpa.EntityManagerSource;
-import org.apache.tapestry5.jpa.JpaConstants;
-import org.apache.tapestry5.jpa.PersistenceUnitConfigurer;
-import org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo;
+import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
+import org.apache.tapestry5.jpa.*;
import org.slf4j.Logger;
-public class EntityManagerSourceImpl implements EntityManagerSource, RegistryShutdownListener
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceProviderResolver;
+import javax.persistence.spi.PersistenceProviderResolverHolder;
+import javax.persistence.spi.PersistenceUnitInfo;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+public class EntityManagerSourceImpl implements EntityManagerSource
{
private final Map<String, EntityManagerFactory> entityManagerFactories = CollectionFactory
.newMap();
@@ -50,10 +49,11 @@
private final List<TapestryPersistenceUnitInfo> persistenceUnitInfos;
- public EntityManagerSourceImpl(final Logger logger, final Resource persistenceDescriptor, PersistenceUnitConfigurer packageNamePersistenceUnitConfigurer,
- final Map<String, PersistenceUnitConfigurer> configuration)
+ public EntityManagerSourceImpl(Logger logger, @Symbol(JpaSymbols.PERSISTENCE_DESCRIPTOR)
+ final Resource persistenceDescriptor, @Local
+ PersistenceUnitConfigurer packageNamePersistenceUnitConfigurer,
+ Map<String, PersistenceUnitConfigurer> configuration)
{
- super();
this.logger = logger;
List<TapestryPersistenceUnitInfo> persistenceUnitInfos = parsePersistenceUnitInfos(persistenceDescriptor);
@@ -62,18 +62,29 @@ public EntityManagerSourceImpl(final Logger logger, final Resource persistenceDe
configureRemaining(persistenceUnitInfos, remainingConfigurations);
- if(persistenceUnitInfos.size() == 1)
+ if (persistenceUnitInfos.size() == 1)
{
packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
- }
- else
+ } else
{
validateUnitInfos(persistenceUnitInfos);
}
this.persistenceUnitInfos = persistenceUnitInfos;
}
+ @PostInjection
+ public void listenForShutdown(RegistryShutdownHub hub)
+ {
+ hub.addRegistryShutdownListener(new Runnable()
+ {
+ public void run()
+ {
+ registryDidShutdown();
+ }
+ });
+ }
+
private void validateUnitInfos(List<TapestryPersistenceUnitInfo> persistenceUnitInfos)
{
final List<String> affectedUnits = F.flow(persistenceUnitInfos).filter(new Predicate<TapestryPersistenceUnitInfo>()
@@ -90,14 +101,14 @@ public String map(TapestryPersistenceUnitInfo info)
}
}).toList();
- if(0 < affectedUnits.size())
+ if (0 < affectedUnits.size())
{
throw new RuntimeException(
String.format(
"Persistence units '%s' are configured to include managed classes that have not been explicitly listed. " +
- "This is forbidden when multiple persistence units are used in the same application. " +
- "Please configure persistence units to exclude unlisted managed classes (e.g. by removing <exclude-unlisted-classes> element) " +
- "and include them explicitly.",
+ "This is forbidden when multiple persistence units are used in the same application. " +
+ "Please configure persistence units to exclude unlisted managed classes (e.g. by removing <exclude-unlisted-classes> element) " +
+ "and include them explicitly.",
InternalUtils.join(affectedUnits)));
}
}
@@ -106,7 +117,7 @@ public String map(TapestryPersistenceUnitInfo info)
{
List<TapestryPersistenceUnitInfo> persistenceUnitInfos = CollectionFactory.newList();
- if(persistenceDescriptor.exists())
+ if (persistenceDescriptor.exists())
{
final PersistenceParser parser = new PersistenceParser();
@@ -115,12 +126,10 @@ public String map(TapestryPersistenceUnitInfo info)
{
inputStream = persistenceDescriptor.openStream();
persistenceUnitInfos = parser.parse(inputStream);
- }
- catch(Exception e)
+ } catch (Exception e)
{
throw new RuntimeException(e);
- }
- finally
+ } finally
{
InternalUtils.close(inputStream);
}
@@ -143,7 +152,7 @@ public String map(TapestryPersistenceUnitInfo info)
{
configurer.configure(info);
- remainingConfigurations.remove(unitName) ;
+ remainingConfigurations.remove(unitName);
}
}
@@ -153,7 +162,7 @@ public String map(TapestryPersistenceUnitInfo info)
private void configureRemaining(List<TapestryPersistenceUnitInfo> persistenceUnitInfos, Map<String, PersistenceUnitConfigurer> remainingConfigurations)
{
- for(Entry<String, PersistenceUnitConfigurer> entry: remainingConfigurations.entrySet())
+ for (Entry<String, PersistenceUnitConfigurer> entry : remainingConfigurations.entrySet())
{
final PersistenceUnitInfoImpl info = new PersistenceUnitInfoImpl(entry.getKey());
@@ -220,7 +229,7 @@ public EntityManager create(final String persistenceUnitName)
return getEntityManagerFactory(persistenceUnitName).createEntityManager();
}
- public void registryDidShutdown()
+ private void registryDidShutdown()
{
final Set<Entry<String, EntityManagerFactory>> entrySet = entityManagerFactories.entrySet();
@@ -230,8 +239,7 @@ public void registryDidShutdown()
try
{
emf.close();
- }
- catch (final Exception e)
+ } catch (final Exception e)
{
logger.error(String.format(
"Failed to close EntityManagerFactory for persistence unit '%s'",
@@ -245,7 +253,7 @@ public void registryDidShutdown()
public List<PersistenceUnitInfo> getPersistenceUnitInfos()
{
- return Collections.<PersistenceUnitInfo> unmodifiableList(persistenceUnitInfos);
+ return Collections.<PersistenceUnitInfo>unmodifiableList(persistenceUnitInfos);
}
}
View
21 tapestry-jpa/src/main/java/org/apache/tapestry5/jpa/JpaModule.java
@@ -43,26 +43,7 @@ public static void bind(final ServiceBinder binder)
{
binder.bind(JpaTransactionAdvisor.class, JpaTransactionAdvisorImpl.class);
binder.bind(PersistenceUnitConfigurer.class, PackageNamePersistenceUnitConfigurer.class).withSimpleId();
- }
-
- public static EntityManagerSource buildEntityManagerSource(final Logger logger,
-
- @Symbol(JpaSymbols.PERSISTENCE_DESCRIPTOR)
- Resource persistenceDescriptor,
-
- @Local
- PersistenceUnitConfigurer persistenceUnitConfigurer,
-
- final Map<String, PersistenceUnitConfigurer> configuration,
-
- final RegistryShutdownHub hub)
- {
- final EntityManagerSourceImpl ems = new EntityManagerSourceImpl(logger, persistenceDescriptor,
- persistenceUnitConfigurer, configuration);
-
- hub.addRegistryShutdownListener(ems);
-
- return ems;
+ binder.bind(EntityManagerSource.class, EntityManagerSourceImpl.class);
}
public static JpaEntityPackageManager buildJpaEntityPackageManager(final Collection<String> packageNames)
View
6 tapestry-spring/src/main/java/org/apache/tapestry5/internal/spring/SpringModuleDef.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -167,9 +167,9 @@ private ObjectCreator constructObjectCreatorForApplicationContext(
{
final CustomizingContextLoader loader = new CustomizingContextLoader(customizer);
- final RegistryShutdownListener shutdownListener = new RegistryShutdownListener()
+ final Runnable shutdownListener = new Runnable()
{
- public void registryDidShutdown()
+ public void run()
{
loader.closeWebApplicationContext(servletContext);
}
View
4 tapestry-upload/src/main/java/org/apache/tapestry5/upload/services/UploadModule.java
@@ -65,9 +65,9 @@ public static MultipartDecoder buildMultipartDecoder(PerthreadManager perthreadM
if (needToAddShutdownListener.getAndSet(false))
{
- shutdownHub.addRegistryShutdownListener(new RegistryShutdownListener()
+ shutdownHub.addRegistryShutdownListener(new Runnable()
{
- public void registryDidShutdown()
+ public void run()
{
FileCleaner.exitWhenFinished();
}

0 comments on commit 940f50b

Please sign in to comment.