Class BasicService

java.lang.Object
jadex.providedservice.impl.service.BasicService
All Implemented Interfaces:
IInternalService, IService

public class BasicService extends Object implements IInternalService
Basic service provide a simple default isValid() implementation that returns true after start service and false afterwards.
  • Field Details

    • idcnt

      protected static long idcnt
      The id counter.
    • internalaccess

      protected jadex.core.impl.Component internalaccess
      Internal access to its component.
    • started

      protected volatile boolean started
      The started state.
    • shutdowned

      protected volatile boolean shutdowned
      The shutdowned state.
    • sid

      protected IServiceIdentifier sid
      The service id.
    • providerid

      protected jadex.core.ComponentIdentifier providerid
      The provider id.
    • type

      protected Class<?> type
    • impltype

      protected Class<?> impltype
    • DEFAULT_SYSTEM_SECURITY

      public static final Security DEFAULT_SYSTEM_SECURITY
  • Constructor Details

    • BasicService

      public BasicService(jadex.core.ComponentIdentifier providerid, Class<?> type, Map<String,Object> properties)
      Create a new service.
    • BasicService

      public BasicService(jadex.core.ComponentIdentifier providerid, Class<?> type, Class<?> impltype, Map<String,Object> properties)
      Create a new service.
  • Method Details

    • isValid

      public jadex.future.IFuture<Boolean> isValid()
      Test if the service is valid.
      Returns:
      True, if service can be used.
    • setServiceIdentifier

      public void setServiceIdentifier(IServiceIdentifier sid)
      Set the service identifier.
      Specified by:
      setServiceIdentifier in interface IInternalService
    • getServiceId

      public IServiceIdentifier getServiceId()
      Get the service id.
      Specified by:
      getServiceId in interface IService
      Returns:
      The service id.
    • invokeMethod

      public jadex.future.IFuture<Object> invokeMethod(String methodname, jadex.common.ClassInfo[] argtypes, Object[] args, jadex.common.ClassInfo rettype)
      Invoke a method reflectively.
      Specified by:
      invokeMethod in interface IService
      Parameters:
      methodname - The method name.
      argtypes - The argument types (can be null if method exists only once).
      args - The arguments.
      rettype - The future return type if it is a specific future.
      Returns:
      The result.
    • getMethodInfos

      public static jadex.future.IFuture<jadex.common.MethodInfo[]> getMethodInfos(IServiceIdentifier sid, ClassLoader cl)
      Get reflective info about the service methods, args, return types.
      Returns:
      The method infos.
    • getMethodInfos

      public jadex.future.IFuture<jadex.common.MethodInfo[]> getMethodInfos()
      Get reflective info about the service methods, args, return types.
      Specified by:
      getMethodInfos in interface IService
      Returns:
      The method infos.
    • getInvokeMethod

      public static Method getInvokeMethod(Class<?> target, ClassLoader cl, String methodname, jadex.common.ClassInfo[] argtypes)
      Get method that should be invoked on target object.
    • getProviderId

      public jadex.core.ComponentIdentifier getProviderId()
      Get the providerid.
      Returns:
      the providerid.
    • setComponentAccess

      public jadex.future.IFuture<Void> setComponentAccess(jadex.core.impl.Component access)
      Sets the access for the component.
      Specified by:
      setComponentAccess in interface IInternalService
      Parameters:
      access - Component access.
    • setPropertyMap

      public void setPropertyMap(Map<String,Object> properties)
      Set the properties.
      Parameters:
      properties - The properties to set.
    • startService

      public jadex.future.IFuture<Void> startService()
      Start the service.
      Specified by:
      startService in interface IInternalService
      Returns:
      A future that is done when the service has completed starting.
    • shutdownService

      public jadex.future.IFuture<Void> shutdownService()
      Shutdown the service.
      Specified by:
      shutdownService in interface IInternalService
      Returns:
      A future that is done when the service has completed its shutdown.
    • generateServiceName

      public static String generateServiceName(Class<?> service)
      Generate a unique name.
      Parameters:
      The - calling service class.
    • createServiceIdentifier

      public static IServiceIdentifier createServiceIdentifier(jadex.core.impl.Component provider, String servicename, Class<?> servicetype, Class<?> serviceimpl, ProvidedServiceInfo info)
      Create a new service identifier for the own component.
    • getInternalAccess

      public jadex.core.impl.Component getInternalAccess()
      Get the internal access.
    • equals

      public boolean equals(Object obj)
      Check if the service is equal. The service is considered equal if the service identifiers match.
      Overrides:
      equals in class Object
      Parameters:
      obj - Object of comparison.
      Returns:
      True, if the object is a service with a matching service identifier.
    • hashCode

      public int hashCode()
      Get the hashcode.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Get a string representation.
      Overrides:
      toString in class Object
    • getMethodTimeout

      public static long getMethodTimeout(Class<?>[] interfaces, Method method, boolean remote)
      Get the default timeout for a method.
    • getInterfaceType

      public Class<?> getInterfaceType()
      Get the interface type.
      Returns:
      The interface type.
    • isUnrestricted

      public static jadex.future.IFuture<Boolean> isUnrestricted(IServiceIdentifier sid, jadex.core.IComponent component, Method method)
      todo: move to some security class Check if a service method is unrestricted. Schedules on component to check this.
      Parameters:
      sid - The service id.
      component - The internal access.
      mi - The method info.
      Returns:
      True, if is unrestricted.
    • getSecurityLevel

      public static Security getSecurityLevel(jadex.core.impl.Component access, ProvidedServiceInfo info, Class<?> implclass, Class<?> type, Method method, IServiceIdentifier sid)
      Find the most specific security setting.