Package jadex.bridge.service
Class BasicService
- java.lang.Object
-
- jadex.bridge.service.BasicService
-
- All Implemented Interfaces:
IInternalService,IService
- Direct Known Subclasses:
BDIAgentFactory,BDIXComponentFactory,BpmnFactory,MicroAgentFactory,MicroserviceFactory
public class BasicService extends java.lang.Object implements IInternalService
Basic service provide a simple default isValid() implementation that returns true after start service and false afterwards.
-
-
Field Summary
Fields Modifier and Type Field Description protected static longidcntThe id counter.protected java.lang.Class<?>impltypeprotected IInternalAccessinternalaccessInternal access to its component.protected IComponentIdentifierprovideridThe provider id.protected booleanshutdownedThe shutdowned state.protected IServiceIdentifiersidThe service id.protected booleanstartedThe started state.protected java.lang.Class<?>type-
Fields inherited from interface jadex.bridge.service.IService
EMPTY_SERVICES
-
-
Constructor Summary
Constructors Constructor Description BasicService(IComponentIdentifier providerid, java.lang.Class<?> type, java.lang.Class<?> impltype, java.util.Map<java.lang.String,java.lang.Object> properties)Create a new service.BasicService(IComponentIdentifier providerid, java.lang.Class<?> type, java.util.Map<java.lang.String,java.lang.Object> properties)Create a new service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ServiceIdentifiercreateServiceIdentifier(IComponentIdentifier providerid, ClassInfo type, ClassInfo[] supertypes, java.lang.String servicename, IResourceIdentifier rid, ServiceScope scope, java.util.Set<java.lang.String> networknames, boolean unrestricted)Create a new service identifier for a potentially remote component.static IServiceIdentifiercreateServiceIdentifier(IInternalAccess provider, java.lang.String servicename, java.lang.Class<?> servicetype, java.lang.Class<?> serviceimpl, IResourceIdentifier rid, ServiceScope scope)Create a new service identifier for the own component.booleanequals(java.lang.Object obj)Check if the service is equal.static java.lang.StringgenerateServiceName(java.lang.Class<?> service)Generate a unique name.java.lang.Class<?>getInterfaceType()Get the interface type.IInternalAccessgetInternalAccess()Get the internal access.static java.lang.reflect.MethodgetInvokeMethod(java.lang.Class<?> target, java.lang.ClassLoader cl, java.lang.String methodname, ClassInfo[] argtypes)Get method that should be invoked on target object.IFuture<MethodInfo[]>getMethodInfos()Get reflective info about the service methods, args, return types.static longgetMethodTimeout(java.lang.Class<?>[] interfaces, java.lang.reflect.Method method, boolean remote)Get the default timeout for a method.java.util.Map<java.lang.String,java.lang.Object>getPropertyMap()Get a service property.IComponentIdentifiergetProviderId()Get the providerid.IServiceIdentifiergetServiceId()Get the service id.inthashCode()Get the hashcode.protected IFuture<java.lang.Void>initNFProperties()Init the non-functional properties (todo: move to other location?)IFuture<java.lang.Object>invokeMethod(java.lang.String methodname, ClassInfo[] argtypes, java.lang.Object[] args, ClassInfo rettype)Invoke a method reflectively.IFuture<java.lang.Boolean>isValid()Test if the service is valid.IFuture<java.lang.Void>setComponentAccess(IInternalAccess access)Sets the access for the component.voidsetPropertyMap(java.util.Map<java.lang.String,java.lang.Object> properties)Set the properties.voidsetServiceIdentifier(IServiceIdentifier sid)Set the service identifier.IFuture<java.lang.Void>shutdownService()Shutdown the service.IFuture<java.lang.Void>startService()Start the service.java.lang.StringtoString()Get a string representation.
-
-
-
Field Detail
-
idcnt
protected static long idcnt
The id counter.
-
internalaccess
protected IInternalAccess 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 IComponentIdentifier providerid
The provider id.
-
type
protected java.lang.Class<?> type
-
impltype
protected java.lang.Class<?> impltype
-
-
Constructor Detail
-
BasicService
public BasicService(IComponentIdentifier providerid, java.lang.Class<?> type, java.util.Map<java.lang.String,java.lang.Object> properties)
Create a new service.
-
BasicService
public BasicService(IComponentIdentifier providerid, java.lang.Class<?> type, java.lang.Class<?> impltype, java.util.Map<java.lang.String,java.lang.Object> properties)
Create a new service.
-
-
Method Detail
-
isValid
public IFuture<java.lang.Boolean> isValid()
Test if the service is valid.
-
setServiceIdentifier
public void setServiceIdentifier(IServiceIdentifier sid)
Set the service identifier.- Specified by:
setServiceIdentifierin interfaceIInternalService
-
getServiceId
public IServiceIdentifier getServiceId()
Get the service id.- Specified by:
getServiceIdin interfaceIService- Returns:
- The service id.
-
invokeMethod
public IFuture<java.lang.Object> invokeMethod(java.lang.String methodname, ClassInfo[] argtypes, java.lang.Object[] args, ClassInfo rettype)
Invoke a method reflectively.- Specified by:
invokeMethodin interfaceIService- 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 IFuture<MethodInfo[]> getMethodInfos()
Get reflective info about the service methods, args, return types.- Specified by:
getMethodInfosin interfaceIService- Returns:
- The method infos.
-
getInvokeMethod
public static java.lang.reflect.Method getInvokeMethod(java.lang.Class<?> target, java.lang.ClassLoader cl, java.lang.String methodname, ClassInfo[] argtypes)Get method that should be invoked on target object.
-
getProviderId
public IComponentIdentifier getProviderId()
Get the providerid.- Returns:
- the providerid.
-
setComponentAccess
public IFuture<java.lang.Void> setComponentAccess(IInternalAccess access)
Sets the access for the component.- Specified by:
setComponentAccessin interfaceIInternalService- Parameters:
access- Component access.
-
initNFProperties
protected IFuture<java.lang.Void> initNFProperties()
Init the non-functional properties (todo: move to other location?)
-
getPropertyMap
public java.util.Map<java.lang.String,java.lang.Object> getPropertyMap()
Get a service property.- Specified by:
getPropertyMapin interfaceIService- Returns:
- The service property (if any).
-
setPropertyMap
public void setPropertyMap(java.util.Map<java.lang.String,java.lang.Object> properties)
Set the properties.- Parameters:
properties- The properties to set.
-
startService
public IFuture<java.lang.Void> startService()
Start the service.- Specified by:
startServicein interfaceIInternalService- Returns:
- A future that is done when the service has completed starting.
-
shutdownService
public IFuture<java.lang.Void> shutdownService()
Shutdown the service.- Specified by:
shutdownServicein interfaceIInternalService- Returns:
- A future that is done when the service has completed its shutdown.
-
generateServiceName
public static java.lang.String generateServiceName(java.lang.Class<?> service)
Generate a unique name.- Parameters:
The- calling service class.
-
createServiceIdentifier
public static IServiceIdentifier createServiceIdentifier(IInternalAccess provider, java.lang.String servicename, java.lang.Class<?> servicetype, java.lang.Class<?> serviceimpl, IResourceIdentifier rid, ServiceScope scope)
Create a new service identifier for the own component.
-
createServiceIdentifier
public static ServiceIdentifier createServiceIdentifier(IComponentIdentifier providerid, ClassInfo type, ClassInfo[] supertypes, java.lang.String servicename, IResourceIdentifier rid, ServiceScope scope, java.util.Set<java.lang.String> networknames, boolean unrestricted)
Create a new service identifier for a potentially remote component.
-
getInternalAccess
public IInternalAccess getInternalAccess()
Get the internal access.
-
equals
public boolean equals(java.lang.Object obj)
Check if the service is equal. The service is considered equal if the service identifiers match.- Overrides:
equalsin classjava.lang.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:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Get a string representation.- Overrides:
toStringin classjava.lang.Object
-
getMethodTimeout
public static long getMethodTimeout(java.lang.Class<?>[] interfaces, java.lang.reflect.Method method, boolean remote)Get the default timeout for a method.
-
getInterfaceType
public java.lang.Class<?> getInterfaceType()
Get the interface type.- Returns:
- The interface type.
-
-