From do-not-reply at jboss.org Tue Jul 13 08:06:50 2010 Content-Type: multipart/mixed; boundary="===============2837639083031591264==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: exo-jcr-commits at lists.jboss.org Subject: [exo-jcr-commits] exo-jcr SVN: r2777 - ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl. Date: Tue, 13 Jul 2010 08:06:50 -0400 Message-ID: <201007131206.o6DC6ogG002294@svn01.web.mwc.hst.phx2.redhat.com> --===============2837639083031591264== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: aparfonov Date: 2010-07-13 08:06:50 -0400 (Tue, 13 Jul 2010) New Revision: 2777 Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/im= pl/RequestHandlerImpl.java ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/im= pl/ResourceBinder.java Log: EXOJCR-824 : = Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/= rest/impl/RequestHandlerImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/i= mpl/RequestHandlerImpl.java 2010-07-13 11:48:53 UTC (rev 2776) +++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/i= mpl/RequestHandlerImpl.java 2010-07-13 12:06:50 UTC (rev 2777) @@ -329,8 +329,6 @@ */ public void stop() { - // TODO improve - ResourceBinder.cleanerStop =3D true; } = // Modified: ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/= rest/impl/ResourceBinder.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/i= mpl/ResourceBinder.java 2010-07-13 11:48:53 UTC (rev 2776) +++ ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/i= mpl/ResourceBinder.java 2010-07-13 12:06:50 UTC (rev 2777) @@ -39,6 +39,7 @@ import org.exoplatform.services.rest.resource.ResourceContainer; import org.exoplatform.services.rest.resource.ResourceDescriptorVisitor; import org.exoplatform.services.rest.uri.UriPattern; +import org.picocontainer.Startable; = import java.util.ArrayList; import java.util.Collections; @@ -65,7 +66,7 @@ * @author Andrey Parfonov * @version $Id: $ */ -public class ResourceBinder +public class ResourceBinder implements Startable { = /** @@ -99,7 +100,7 @@ } }; = - static boolean cleanerStop =3D false; + protected boolean cleanerStop =3D false; = protected class ResourceCleaner implements Runnable { @@ -190,6 +191,8 @@ /** Resource listeners. */ protected final List resourceListeners =3D new ArrayL= ist(); = + protected final ExoContainer container; + public ResourceBinder(ExoContainerContext containerContext) throws Exce= ption { this(containerContext, null); @@ -203,54 +206,13 @@ */ public ResourceBinder(ExoContainerContext containerContext, MethodInvok= erFactory invokerFactory) throws Exception { - this(containerContext, null, invokerFactory); - } - - @SuppressWarnings("unchecked") - protected ResourceBinder(ExoContainerContext containerContext, Resource= Cleaner cleaner, - MethodInvokerFactory invokerFactory) throws Exception - { this.invokerFactory =3D invokerFactory; - // Initialize RuntimeDelegate instance // This is first component in life cycle what needs. // TODO better solution to initialize RuntimeDelegate RuntimeDelegate.setInstance(new RuntimeDelegateImpl()); rd =3D RuntimeDelegate.getInstance(); - - ExoContainer container =3D containerContext.getContainer(); - - // Lookup Applications - List al =3D container.getComponentInstancesOfType(Appli= cation.class); - for (Application a : al) - { - try - { - addApplication(a); - } - catch (Exception e) - { - LOG.error("Failed add JAX-RS application " + a.getClass().getN= ame(), e); - } - } - - // Lookup all object which implements ResourceContainer interface and - // process them to be add as root resources. - for (Object resource : container.getComponentInstancesOfType(Resourc= eContainer.class)) - { - try - { - addResource(resource, null); - } - catch (Exception e) - { - LOG.error("Failed add JAX-RS resource " + resource.getClass().= getName(), e); - } - } - - Thread thread =3D new Thread(cleaner =3D=3D null ? new ResourceClean= er(60) : cleaner); - thread.setDaemon(true); - thread.start(); + container =3D containerContext.getContainer(); } = /** @@ -716,4 +678,71 @@ return null !=3D removeResource(path); } = + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + public void start() + { + // Lookup Applications + List al =3D container.getComponentInstancesOfType(Appli= cation.class); + for (Application a : al) + { + try + { + addApplication(a); + } + catch (Exception e) + { + LOG.error("Failed add JAX-RS application " + a.getClass().getN= ame(), e); + } + } + + // Lookup all object which implements ResourceContainer interface and + // process them to be add as root resources. + for (Object resource : container.getComponentInstancesOfType(Resourc= eContainer.class)) + { + try + { + addResource(resource, null); + } + catch (Exception e) + { + LOG.error("Failed add JAX-RS resource " + resource.getClass().= getName(), e); + } + } + + startResourceCleaner(); + } + + /** + * {@inheritDoc} + */ + public void stop() + { + cleanerStop =3D true; + } + + /** + * Start resource cleaner which periodically check all available resour= ces + * and remove expired. Expired date may be specified by adding special + * property (see {@link #RESOURCE_EXPIRED}) when resource added. In exa= mple + * below resource will be expired in one minute. By default resources c= heck + * one time per minute so live time less than one minute is not guarant= eed. + * + *
+    * ResourceBinder binder =3D ...
+    * Class resource =3D ...
+    * MultivaluedMap properties =3D new MultivaluedMapImpl=
();
+    * properties.putSingle("resource.expiration.date",
+    *    Long.toString(System.currentTimeMillis() + 60000L));
+    * binder.addResource(resource, properties);
+    * 
+ */ + protected void startResourceCleaner() + { + Thread thread =3D new Thread(new ResourceCleaner(60)); + thread.setDaemon(true); + thread.start(); + } } --===============2837639083031591264==--