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 long
idcnt
The id counter.protected java.lang.Class<?>
impltype
protected IInternalAccess
internalaccess
Internal access to its component.protected IComponentIdentifier
providerid
The provider id.protected boolean
shutdowned
The shutdowned state.protected IServiceIdentifier
sid
The service id.protected boolean
started
The 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 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.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.boolean
equals(java.lang.Object obj)
Check if the service is equal.static java.lang.String
generateServiceName(java.lang.Class<?> service)
Generate a unique name.java.lang.Class<?>
getInterfaceType()
Get the interface type.IInternalAccess
getInternalAccess()
Get the internal access.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.IFuture<MethodInfo[]>
getMethodInfos()
Get reflective info about the service methods, args, return types.static long
getMethodTimeout(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.IComponentIdentifier
getProviderId()
Get the providerid.IServiceIdentifier
getServiceId()
Get the service id.int
hashCode()
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.void
setPropertyMap(java.util.Map<java.lang.String,java.lang.Object> properties)
Set the properties.void
setServiceIdentifier(IServiceIdentifier sid)
Set the service identifier.IFuture<java.lang.Void>
shutdownService()
Shutdown the service.IFuture<java.lang.Void>
startService()
Start the service.java.lang.String
toString()
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:
setServiceIdentifier
in interfaceIInternalService
-
getServiceId
public IServiceIdentifier getServiceId()
Get the service id.- Specified by:
getServiceId
in 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:
invokeMethod
in 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:
getMethodInfos
in 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:
setComponentAccess
in 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:
getPropertyMap
in 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:
startService
in 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:
shutdownService
in 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:
equals
in 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:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Get a string representation.- Overrides:
toString
in 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.
-
-