Package ai.thinkingrobots.trade
Class TRADE
java.lang.Object
ai.thinkingrobots.trade.TRADE
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaccessToTRADEServices(String credentials, boolean on) Makes all functions with TRADEService in the container part of the available services (can be used to perform operations on remote containers by using "local" constraints on calls)static voidaddServiceGroups(TRADEServiceInfo service, Collection<String> groups) Adds new groups to the current service groupsstatic voidafterService(TRADEServiceInfo wrapperService, TRADEServiceInfo serviceToWrap) Calls a wrapper service after every call of the service to wrap.static voidbeforeService(TRADEServiceInfo wrapperService, TRADEServiceInfo serviceToWrap) Calls a wrapper service before every call of the service to wrap.static voidstatic voidderegister(Object component) Deregisters a previously registered componentstatic voidfindInterfaces(String credentials) Scans the hosts interfaces and all available IPs, and adds them to the list of Available Interface Addressesstatic TRADEServiceInfogetAvailableService(TRADEServiceConstraints constraints) Returns single service that matches the pattern in the system subject to constraintsstatic Collection<TRADEServiceInfo>Returns a list of all available services system-widestatic Collection<TRADEServiceInfo>getAvailableServices(TRADEServiceConstraints constraints) Returns all services that match the pattern in the system subject to constraintsstatic Collection<TRADEServiceInfo>getAvailableServices(Class<?> annotationType, TRADEServiceConstraints constraints) Deprecated.static voidloadConfig(String credentials, InputStream configStream) Sets up basic values from the TRADE "trade.properties" config filestatic UUIDlockServicesContainAll(Collection<String> groups) Locks all services that contain all group names in "groups"static UUIDlockServicesContainOne(Collection<String> groups) Locks all services that contain of the group names in "groups"static voidnotify(Object requester, String[][] callconditions, TRADEServiceConstraints constraints, String callbackfunction, Class<?>... callbacktypes) static Collection<TRADEServiceInfo>registerAllServices(Object component, String group) Registers all methods ofcomponentthat are annotated with@TRADEServiceand places them into groupstatic Collection<TRADEServiceInfo>registerAllServices(Object component, Collection<String> groups) Registers all methods ofcomponentthat are annotated with@TRADEServiceand places them into groupsstatic voidreleaseLock(UUID locktorelease) Releases the lock (if it is in use)static voidremoveServiceGroups(TRADEServiceInfo service, Collection<String> groups) Removes a set of group names from the current service groupsstatic voidDeprecated.static voidresetServiceGroups(TRADEServiceInfo service) Resets the service's associated groups to the initial group names in the annotationsstatic voidsetBroadcast(String credentials, boolean on) Turns container broadcasting on or off to enable discovery of this containerstatic voidsetDiscovery(String credentials, boolean on) Turns container discvoery on or offstatic voidsetEncryption(String credentials, boolean on) Toggles whether calls are encryptedstatic voidsetServiceGroups(TRADEServiceInfo service, Collection<String> groups) Replace the current groups associated with the service with the new groupsstatic voidshutdownTRADE(String credentials) Brute-force system exit which shuts down the whole JVMstatic voidstartListenForConnections(String credentials, String ip, int port) Starts accepting incoming connections on PORT listening to all interfacesstatic voidstopListenForConnections(String credentials) Stops accepting new incoming connections
-
Method Details
-
reset
Deprecated.Initializes the TRADE system- Parameters:
credentials- the credentials for using TRADE infrastructure methods- Throws:
TRADENotAuthorizedException- throws TRADENotAuthorizedException if credentials are not validTRADEException
-
loadConfig
Sets up basic values from the TRADE "trade.properties" config file- Parameters:
credentials- the credentials for using TRADE infrastructure methodsconfigStream- the stream from which to read the configurations- Throws:
TRADEException- throws TRADENotAuthorizedException if credentials are not valid
-
accessToTRADEServices
Makes all functions with TRADEService in the container part of the available services (can be used to perform operations on remote containers by using "local" constraints on calls)- Parameters:
credentials- the credentials for using TRADE infrastructure methodson- whether to turn access on or off- Throws:
TRADEException- throws TRADENotAuthorizedException if credentials are not valid
-
findInterfaces
Scans the hosts interfaces and all available IPs, and adds them to the list of Available Interface Addresses- Parameters:
credentials- the credentials for using TRADE infrastructure methods- Throws:
TRADEException- throws TRADENotAuthorizedException if credentials are not valid
-
setEncryption
Toggles whether calls are encrypted- Parameters:
credentials- the credentials for using TRADE infrastructure methodson- if true encryption is used otherwise it is not- Throws:
TRADEException- throws TRADENotAuthorizedException if credentials are not valid
-
shutdownTRADE
Brute-force system exit which shuts down the whole JVM- Parameters:
credentials- the credentials for using TRADE infrastructure methods- Throws:
TRADEException- if caller does not have credentials to shut down TRADE
-
setBroadcast
Turns container broadcasting on or off to enable discovery of this container- Parameters:
credentials- the credentials for using TRADE infrastructure methodson- whether broadcasting container information is on or off- Throws:
TRADEException- throws TRADENotAuthorizedException if credentials are not valid
-
setDiscovery
Turns container discvoery on or off- Parameters:
credentials- the credentials for using TRADE infrastructure methodson- whether discovery and the subsequent connection attempt is on or off- Throws:
TRADEException- throws TRADENotAuthorizedException if credentials are not valid
-
registerAllServices
public static Collection<TRADEServiceInfo> registerAllServices(Object component, String group) throws TRADEException Registers all methods ofcomponentthat are annotated with@TRADEServiceand places them into group- Parameters:
component- the objects whose TRADEServices will be registeredgroup- collection of group names to be associated with all services- Returns:
- collection of TSIs that were added as a result of registration
- Throws:
TRADEException- throws exception if no component is supplied or the component is already registered
-
registerAllServices
public static Collection<TRADEServiceInfo> registerAllServices(Object component, Collection<String> groups) throws TRADEException Registers all methods ofcomponentthat are annotated with@TRADEServiceand places them into groups- Parameters:
component- the object whose methods will be registeredgroups- collection of group names to be associated with all services- Returns:
- collection of TSIs that were added as a result of registration
- Throws:
TRADEException- throws exception if no component is supplied or the component is already registered
-
deregister
Deregisters a previously registered component- Parameters:
component- the previously registered component- Throws:
TRADEException- throws exception if the component was not registered or a failure occurred during deregistration
-
setServiceGroups
public static void setServiceGroups(TRADEServiceInfo service, Collection<String> groups) throws TRADEException Replace the current groups associated with the service with the new groups- Parameters:
service- the service handlegroups- the new group names to be associated with the service- Throws:
TRADEException- throws exception if the service is locked and group changes are not allowed
-
removeServiceGroups
public static void removeServiceGroups(TRADEServiceInfo service, Collection<String> groups) throws TRADEException Removes a set of group names from the current service groups- Parameters:
service- the service handlegroups- the group names to be removed- Throws:
TRADEException- throws exception if the service is locked and group changes are not allowed
-
addServiceGroups
public static void addServiceGroups(TRADEServiceInfo service, Collection<String> groups) throws TRADEException Adds new groups to the current service groups- Parameters:
service- the service handlegroups- the group names to be added- Throws:
TRADEException- throws exception if the service is locked and group changes are not allowed
-
resetServiceGroups
Resets the service's associated groups to the initial group names in the annotations- Parameters:
service- the service handle- Throws:
TRADEException- throws exception if the service is locked and group changes are not allowed
-
releaseLock
Releases the lock (if it is in use)- Parameters:
locktorelease- the lock to be released- Throws:
TRADEException
-
lockServicesContainOne
Locks all services that contain of the group names in "groups"- Parameters:
groups- the services that have at least one name in "groups" in common- Returns:
- the a lock object if all services that are eligible could be locked locally and in remote containers, null otherwise
-
lockServicesContainAll
Locks all services that contain all group names in "groups"- Parameters:
groups- the services that contain all names in "groups"- Returns:
- the a lock object if all services that are eligible could be locked locally and in remote containers, null otherwise
-
getAvailableServices
Returns a list of all available services system-wide- Returns:
- set of TRADEServiceInfos for services that match provide constraints
-
getAvailableServices
public static Collection<TRADEServiceInfo> getAvailableServices(TRADEServiceConstraints constraints) Returns all services that match the pattern in the system subject to constraints- Parameters:
constraints- the constraints for the services- Returns:
- set of TRADEServiceInfos for services that match provide constraints
-
getAvailableService
public static TRADEServiceInfo getAvailableService(TRADEServiceConstraints constraints) throws TRADEException Returns single service that matches the pattern in the system subject to constraints- Parameters:
constraints- the constraints for the services- Returns:
- set of TRADEServiceInfos for services that match provide constraints
- Throws:
TRADEException- if constraints passed in do not define unique service
-
getAvailableServices
@Deprecated public static Collection<TRADEServiceInfo> getAvailableServices(Class<?> annotationType, TRADEServiceConstraints constraints) Deprecated.Returns all services that have the given annotations subject to additional constraints- Parameters:
annotationType- the annotation type on the servicesconstraints- the constraints on the services- Returns:
- set of TRADEServiceInfos for services that match provide constraints for given annotation type
-
startListenForConnections
public static void startListenForConnections(String credentials, String ip, int port) throws TRADEException Starts accepting incoming connections on PORT listening to all interfaces- Parameters:
credentials- the credentials for using infrastructure callsip- the ip address of the host running this containerport- the serverport to start listening in on, 0 for wildcard.- Throws:
TRADEException- if unable to start the server socket or the credentials are incorrect
-
stopListenForConnections
Stops accepting new incoming connections- Parameters:
credentials- the credentials for using infrastructure calls- Throws:
TRADEException- if unable to stop the server socket or the credentials are incorrect
-
cancel
- Throws:
TRADEException
-
notify
public static void notify(Object requester, String[][] callconditions, TRADEServiceConstraints constraints, String callbackfunction, Class<?>... callbacktypes) throws TRADEException - Throws:
TRADEException
-
beforeService
public static void beforeService(TRADEServiceInfo wrapperService, TRADEServiceInfo serviceToWrap) throws TRADEException Calls a wrapper service before every call of the service to wrap. Wrapper service has access to the arguments passed into the wrapped service.- Parameters:
wrapperService- TSI of service to call beforeserviceToWrapserviceToWrap- TSI of service whose calls will be wrrapped bywrapperService- Throws:
TRADEException- if wrapper service is not var args
-
afterService
public static void afterService(TRADEServiceInfo wrapperService, TRADEServiceInfo serviceToWrap) throws TRADEException Calls a wrapper service after every call of the service to wrap. Wrapper service has access to the arguments passed into the wrapped service as well as its return value.- Parameters:
wrapperService- TSI of service to call beforeserviceToWrapserviceToWrap- TSI of service whose calls will be wrrapped bywrapperService- Throws:
TRADEException
-