Class TRADE

java.lang.Object
ai.thinkingrobots.trade.TRADE

public final class TRADE extends Object
  • Method Details

    • reset

      @Deprecated public static void reset(String credentials) throws TRADEException
      Deprecated.
      Initializes the TRADE system
      Parameters:
      credentials - the credentials for using TRADE infrastructure methods
      Throws:
      TRADENotAuthorizedException - throws TRADENotAuthorizedException if credentials are not valid
      TRADEException
    • loadConfig

      public static void loadConfig(String credentials, InputStream configStream) throws TRADEException
      Sets up basic values from the TRADE "trade.properties" config file
      Parameters:
      credentials - the credentials for using TRADE infrastructure methods
      configStream - the stream from which to read the configurations
      Throws:
      TRADEException - throws TRADENotAuthorizedException if credentials are not valid
    • accessToTRADEServices

      public static void accessToTRADEServices(String credentials, boolean on) throws TRADEException
      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 methods
      on - whether to turn access on or off
      Throws:
      TRADEException - throws TRADENotAuthorizedException if credentials are not valid
    • findInterfaces

      public static void findInterfaces(String credentials) throws TRADEException
      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

      public static void setEncryption(String credentials, boolean on) throws TRADEException
      Toggles whether calls are encrypted
      Parameters:
      credentials - the credentials for using TRADE infrastructure methods
      on - if true encryption is used otherwise it is not
      Throws:
      TRADEException - throws TRADENotAuthorizedException if credentials are not valid
    • shutdownTRADE

      public static void shutdownTRADE(String credentials) throws TRADEException
      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

      public static void setBroadcast(String credentials, boolean on) throws TRADEException
      Turns container broadcasting on or off to enable discovery of this container
      Parameters:
      credentials - the credentials for using TRADE infrastructure methods
      on - whether broadcasting container information is on or off
      Throws:
      TRADEException - throws TRADENotAuthorizedException if credentials are not valid
    • setDiscovery

      public static void setDiscovery(String credentials, boolean on) throws TRADEException
      Turns container discvoery on or off
      Parameters:
      credentials - the credentials for using TRADE infrastructure methods
      on - 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 of component that are annotated with @TRADEService and places them into group
      Parameters:
      component - the objects whose TRADEServices will be registered
      group - 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 of component that are annotated with @TRADEService and places them into groups
      Parameters:
      component - the object whose methods will be registered
      groups - 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

      public static void deregister(Object component) throws TRADEException
      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 handle
      groups - 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 handle
      groups - 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 handle
      groups - the group names to be added
      Throws:
      TRADEException - throws exception if the service is locked and group changes are not allowed
    • resetServiceGroups

      public static void resetServiceGroups(TRADEServiceInfo service) throws TRADEException
      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

      public static void releaseLock(UUID locktorelease) throws TRADEException
      Releases the lock (if it is in use)
      Parameters:
      locktorelease - the lock to be released
      Throws:
      TRADEException
    • lockServicesContainOne

      public static UUID lockServicesContainOne(Collection<String> groups)
      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

      public static UUID lockServicesContainAll(Collection<String> groups)
      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

      public static Collection<TRADEServiceInfo> 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 services
      constraints - 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 calls
      ip - the ip address of the host running this container
      port - 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

      public static void stopListenForConnections(String credentials) throws TRADEException
      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

      public static void cancel(Object requester, String[][] callconditions) throws TRADEException
      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 before serviceToWrap
      serviceToWrap - TSI of service whose calls will be wrrapped by wrapperService
      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 before serviceToWrap
      serviceToWrap - TSI of service whose calls will be wrrapped by wrapperService
      Throws:
      TRADEException