Class JiniServiceFactoryBean

java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean
org.openspaces.core.jini.JiniServiceFactoryBean
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean, org.springframework.beans.factory.InitializingBean

public class JiniServiceFactoryBean extends org.springframework.beans.factory.config.AbstractFactoryBean implements org.aopalliance.intercept.MethodInterceptor
JiniServiceFactoryBean for Jini environments. The class is made up from various samples found on jini.org customized in a Spring specific way. The search will be executed using the provided ServiceTemplate or, if it is null, one will be created using the serviceClass and serviceName. If the lookup operation times out (30 seconds by default), a null service will be returned. For most cases the serviceClass and serviceNames are enough and hide the jini details from the client.

The factoryBean can be configured to do a lookup each time before returning the object type by setting the "singleton" property to false.

The service factory can be configured to return a smart proxy that will try and perform another lookup in case of an invocation exception (see setSmartProxy(boolean). The retry count can be controlled using setRetryCountOnFailure(int).

Author:
kimchy
  • Constructor Details

    • JiniServiceFactoryBean

      public JiniServiceFactoryBean()
  • Method Details

    • getObjectType

      public Class<?> getObjectType()
      Specified by:
      getObjectType in interface org.springframework.beans.factory.FactoryBean
      Specified by:
      getObjectType in class org.springframework.beans.factory.config.AbstractFactoryBean
    • createInstance

      protected Object createInstance() throws Exception
      Creates an instance of the service. Performs a lookup (using lookupService() and if smart proxy is used, will wrap the returned service with a proxy that performs lookups in case of failures.
      Specified by:
      createInstance in class org.springframework.beans.factory.config.AbstractFactoryBean
      Throws:
      Exception
    • invoke

      public Object invoke(org.aopalliance.intercept.MethodInvocation methodInvocation) throws Throwable
      When using smart proxy, wraps the invocation of a service method and in case of failure will try and perform another lookup for the service.
      Specified by:
      invoke in interface org.aopalliance.intercept.MethodInterceptor
      Throws:
      Throwable
    • lookupService

      protected Object lookupService() throws Exception
      A helper method to lookup the service.
      Throws:
      Exception
    • setSmartProxy

      public void setSmartProxy(boolean smartProxy)
      Sets if this proxy will be a smart proxy. When this value is set to true the service found will be wrapped with a smart proxy that will detect failures and try to lookup the service again in such cases. Defaults to false.
    • setRetryCountOnFailure

      public void setRetryCountOnFailure(int retryCountOnFailure)
      Sets the number of successive method invocation lookup retry count in case of a failure. Defaults to 3.
    • getGroups

      public String[] getGroups()
      Returns the groups.
    • setGroups

      public void setGroups(String[] groups)
      The groups to set
    • getLocators

      public String[] getLocators()
      Returns the locators.
    • setLocators

      public void setLocators(String[] locators)
      Sets the locators.
    • getServiceClass

      public Class<?> getServiceClass()
      Returns:
      Returns the serviceClass.
    • setServiceClass

      public void setServiceClass(Class<?> serviceClass)
      Parameters:
      serviceClass - The serviceClass to set.
    • getServiceName

      public String getServiceName()
      Returns:
      Returns the serviceName.
    • setServiceName

      public void setServiceName(String serviceName)
      Parameters:
      serviceName - The serviceName to set.
    • getTemplate

      public ServiceTemplate getTemplate()
      Returns:
      Returns the template.
    • setTemplate

      public void setTemplate(ServiceTemplate template)
      Parameters:
      template - The template to set.
    • getTimeout

      public long getTimeout()
      The timeout to wait looking up the service
    • setTimeout

      public void setTimeout(long timeout)
      The timeout to wait looking up the service