com.ibm.ia.agent

Class Agent

  • java.lang.Object
    • com.ibm.ia.common.BaseComponent
      • com.ibm.ia.agent.Agent
  • All Implemented Interfaces:
    com.ibm.ia.agent.AgentService, com.ibm.ia.common.BaseComponentService, Extension, SolutionComponent
    Direct Known Subclasses:
    EntityAgent


    public abstract class Agent
    extends com.ibm.ia.common.BaseComponent
    implements com.ibm.ia.agent.AgentService
    The base class for all agent implementations. Agents perform units of work in response to incoming Events.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected com.ibm.ia.common.impl.DelayValue delayValue 
      • Fields inherited from class com.ibm.ia.common.BaseComponent

        dataProviderResolver, defTimeService, entityResolver, eventResolver, localQueryService, modelFactory, objEntityResolver, objEventResolver, requiredEngineVersion, solInfo
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void activated()
      An agent has been activated on a partition for event processing.
      boolean agentPerformsSelfMonitoring() 
      boolean cancelSchedule(java.lang.String key)
      Cancel a previously scheduled callback.
      void clearEngineTime(java.lang.String id) 
      void clearEventTTL(java.lang.String id) 
      void clearOutboundEvents() 
      <T extends com.ibm.ia.model.Entity> 
      com.ibm.ia.model.Relationship<T>
      createRelationship(java.lang.Class<T> entity, java.lang.String key)
      Convenience method to create Relationships
      <T extends com.ibm.ia.model.Entity> 
      com.ibm.ia.model.Relationship<T>
      createRelationship(T t)
      Convenience method to create Relationships
      void deactivated()
      Notification when an agent has been deactivated from a partition.
      void emit(com.ibm.ia.model.Event event)
      Emit an event.
      AgentDescriptor getAgentDescriptor()
      Get the descriptor for the agent.
      protected java.lang.String getAgentProperty(java.lang.String propName, java.lang.String agentQualifier) 
      Version getAgentVersion() 
      protected com.ibm.ia.time.CalendarDuration getCalendarDuration(java.lang.String duration, com.ibm.ia.time.CalendarDuration defaultDuration) 
      EventReference getCurrentEventReference(int ttl) 
      java.util.List<com.ibm.ia.common.GenericEvent> getEmittedEvents() 
      java.time.ZonedDateTime getEngineTime(java.lang.String id) 
      protected EntityFactory getEntityFactory()
      Deprecated.  
      protected EventFactory getEventFactory()
      Deprecated.  
      int getEventTTL(java.lang.String id) 
      protected com.ibm.rules.engine.service.EngineService[] getFactoryServices() 
      com.ibm.ia.common.GenericEntity getGenericEntity(com.ibm.ia.model.Entity entity) 
      java.lang.Object getGlobalValue(java.lang.String name)
      Gets the value of the given global variable name.
      JobService getJobService()
      Returns the agent global runtime service for scheduling analytics jobs.
      protected com.ibm.ia.common.spi.IModelFactory getModelFactory()
      Deprecated. 
      prevent use by customer Agents
      java.lang.String getRequiredEngineVersion() 
      SolutionDescriptor getSolutionDescriptor()
      Get solution-specific information.
      java.util.Map<java.lang.String,java.lang.String> getSolutionProperties(java.util.Collection<java.lang.String> propertyNames)
      Get multiple solution properties for the solution to which this agent belongs.
      java.lang.String getSolutionProperty(java.lang.String propertyName)
      Get a solution property for the solution to which this agent belongs.
      java.lang.String getSolutionProperty(java.lang.String propertyName, java.lang.String defaultValue)
      Get a solution property for the solution to which this agent belongs.
      SpatialService getSpatialService()
      Get the Geospatial service library.
      com.ibm.ia.engine.service.DefaultTimeService getTimeService() 
      com.ibm.ia.engine.service.DefaultTimeService getTimeService(java.lang.String _requiredEngineVersion, java.time.ZoneId _zoneId) 
      boolean hasUserDefinedCookie() 
      void init()
      One-time initialization for new agents deployed in the system.
      com.ibm.ia.engine.runtime.EventEngineDefinition initializeEngineDefinition(java.lang.String _requiredEngineVersion, java.time.ZoneId _zoneId) 
      boolean isThrowableIgnored() 
      java.io.InputStream loadRulesetArchive() 
      void printToLog(java.util.logging.Level level, java.lang.String message)
      Write a message to the log using a specific logging level.
      void printToLog(java.lang.String message)
      Write a message to the log.
      void printToLog(java.lang.Throwable throwable)
      Log a java.lang.Throwable.
      abstract void process(com.ibm.ia.model.Event event)
      Entry point into agent.
      void process(java.lang.String key, java.lang.String cookie)
      Entry point for an agent that is invoked as a result of a previously scheduled callback.
      com.ibm.ia.model.Event resolveEvent(EventReference ref) 
      java.lang.String schedule(int delay, java.util.concurrent.TimeUnit unit, java.lang.String cookie)
      Schedule a deferred call to the Agent process(String key, String cookie) method.
      java.lang.String schedule(java.time.ZonedDateTime dateTime, java.lang.String cookie)
      Schedule a deferred call to the Agent process(String key, String cookie) method.
      void setEngineTime(java.time.ZonedDateTime time, java.lang.String id) 
      void setEventTTL(int ttl, java.lang.String id) 
      void setRequiredEngineVersion(java.lang.String requiredEngineVersion) 
      java.lang.String toString() 
      boolean useMonitorWarning() 
      • Methods inherited from class com.ibm.ia.common.BaseComponent

        emit, getConceptFactory, getEventInstance, getEventResolver, getLocalQueryService, getModelSerializer, getObjectEntityResolver, getObjectEventResolver, getTimeService, processOutboundEvents, resetResolvers, setEntityResolver, setEntityScopedQS, setModelFactory, setObjectEntityResolver, setSolutionDescriptor
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • delayValue

        protected com.ibm.ia.common.impl.DelayValue delayValue
    • Method Detail

      • init

        public void init()
        One-time initialization for new agents deployed in the system. The init() method is called before the solution has been enabled to receive events.
      • activated

        public void activated()
        An agent has been activated on a partition for event processing. Users may override this method. The activated() method is called the first time the agent is required to process an event on a particular partition. The activate method may be invoked multiple times, but is only invoked on agents that have never been activated, or on agents that have been previously deactivated.
      • deactivated

        public void deactivated()
        Notification when an agent has been deactivated from a partition. Users may override this method. The deactivated() method is called when a agent is removed from event processing for a partition. This method will only be called on agent that have previously been activated.
        Specified by:
        deactivated in interface com.ibm.ia.common.BaseComponentService
        Overrides:
        deactivated in class com.ibm.ia.common.BaseComponent
      • getJobService

        public final JobService getJobService()
        Returns the agent global runtime service for scheduling analytics jobs.
        Throws:
        java.lang.UnsupportedOperationException - if called outside a valid execution context
        Returns:
        The agent global runtime service.
      • getGlobalValue

        public final java.lang.Object getGlobalValue(java.lang.String name)
        Gets the value of the given global variable name.
        Parameters:
        name - The name of the variable to get.
        Returns:
        The variable value or null.
      • getSolutionDescriptor

        public final SolutionDescriptor getSolutionDescriptor()
        Get solution-specific information.
        Specified by:
        getSolutionDescriptor in interface com.ibm.ia.agent.AgentService
        Specified by:
        getSolutionDescriptor in interface Extension
        Overrides:
        getSolutionDescriptor in class com.ibm.ia.common.BaseComponent
        Returns:
        SolutionDescriptor containing solution details.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • process

        public void process(java.lang.String key,
                   java.lang.String cookie)
                     throws AgentException
        Entry point for an agent that is invoked as a result of a previously scheduled callback.
        Throws:
        AgentException
        Parameters:
        key - The identifier of the schedule to which this invocation applies.
        cookie - A user-defined string supplied to the schedule method for this scheduled callback.
      • getEventFactory

        protected EventFactory getEventFactory()
        Deprecated. 
      • getEntityFactory

        protected EntityFactory getEntityFactory()
        Deprecated. 
      • getModelFactory

        protected com.ibm.ia.common.spi.IModelFactory getModelFactory()
        Deprecated. prevent use by customer Agents
        Overrides:
        getModelFactory in class com.ibm.ia.common.BaseComponent
      • getSolutionProperty

        public java.lang.String getSolutionProperty(java.lang.String propertyName)
                                             throws java.lang.IllegalArgumentException
        Get a solution property for the solution to which this agent belongs.
        Specified by:
        getSolutionProperty in interface com.ibm.ia.agent.AgentService
        Specified by:
        getSolutionProperty in interface com.ibm.ia.common.BaseComponentService
        Specified by:
        getSolutionProperty in interface Extension
        Overrides:
        getSolutionProperty in class com.ibm.ia.common.BaseComponent
        Throws:
        java.lang.IllegalArgumentException - if the property name is not recognized.
        Parameters:
        propertyName - The name of the property.
        Returns:
        The value of the property set or null if not set.
      • getSolutionProperty

        public java.lang.String getSolutionProperty(java.lang.String propertyName,
                                           java.lang.String defaultValue)
                                             throws java.lang.IllegalArgumentException
        Get a solution property for the solution to which this agent belongs.
        Specified by:
        getSolutionProperty in interface com.ibm.ia.agent.AgentService
        Specified by:
        getSolutionProperty in interface com.ibm.ia.common.BaseComponentService
        Specified by:
        getSolutionProperty in interface Extension
        Overrides:
        getSolutionProperty in class com.ibm.ia.common.BaseComponent
        Throws:
        java.lang.IllegalArgumentException - if the property name is not recognized.
        java.lang.UnsupportedOperationException - if called outside a valid execution context
        Parameters:
        propertyName - The name of the property.
        defaultValue - The value to use if the property is not set.
        Returns:
        The value of the property, if set. Otherwise, the value of the defaultValue parameter is returned.
      • getSolutionProperties

        public java.util.Map<java.lang.String,java.lang.String> getSolutionProperties(java.util.Collection<java.lang.String> propertyNames)
        Get multiple solution properties for the solution to which this agent belongs.
        Specified by:
        getSolutionProperties in interface com.ibm.ia.agent.AgentService
        Specified by:
        getSolutionProperties in interface com.ibm.ia.common.BaseComponentService
        Specified by:
        getSolutionProperties in interface Extension
        Overrides:
        getSolutionProperties in class com.ibm.ia.common.BaseComponent
        Throws:
        java.lang.UnsupportedOperationException - if called outside a valid execution context
        Parameters:
        propertyNames - The names of the properties to retrieve.
        Returns:
        The names and values of the requested properties. Undefined properties are not included in the result.
      • emit

        public void emit(com.ibm.ia.model.Event event)
                  throws AgentException
        Emit an event. The default event time is assumed to be the current time.
        Throws:
        AgentException
        Parameters:
        event - The event to emit.
      • cancelSchedule

        public boolean cancelSchedule(java.lang.String key)
                               throws AgentException
        Cancel a previously scheduled callback.
        Throws:
        AgentException
        java.lang.UnsupportedOperationException - if called outside a valid execution context
        Parameters:
        key - The key returned by schedule() to be cancelled.
        Returns:
        true If the scheduled callback was successfully removed.
      • schedule

        public java.lang.String schedule(int delay,
                                java.util.concurrent.TimeUnit unit,
                                java.lang.String cookie)
                                  throws AgentException
        Schedule a deferred call to the Agent process(String key, String cookie) method. Override the process(String key, String cookie) method in your agent to be called when the delay has expired.
        Throws:
        java.lang.UnsupportedOperationException - if called outside a valid execution context
        AgentException
        Parameters:
        delay - The number of units (see unit parameter) in the future to delay. The minimum future time is 1 second. Partial seconds are truncated. The maximum future time is Integer.MAX_VALUE seconds, larger schedules will be truncated.
        unit - The java.util.Concurrent.TimeUnit to use. For convenience you can specify the delay in various units, which will be converted to seconds.
        cookie - A String which the agent can create which will be passed to the process(String key, String cookie) method.
        Returns:
        A String which can be used as the input to cancelScheduled
      • schedule

        public java.lang.String schedule(java.time.ZonedDateTime dateTime,
                                java.lang.String cookie)
                                  throws AgentException
        Schedule a deferred call to the Agent process(String key, String cookie) method. Override the process(String key, String cookie) method in your agent to be called when the dateTime arrives.
        Throws:
        java.lang.UnsupportedOperationException - if called outside a valid execution context
        AgentException
        Parameters:
        dateTime - A ZonedDateTime in the future the minimum future time is 1 second. Partial seconds are truncated. The maximum future time is Integer.MAX_VALUE seconds, larger schedules will be truncated.
        cookie - A String which the agent can create which will be passed to the process(String key, String cookie) method.
        Returns:
        A String which can be used as the input to cancelScheduled.
      • getSpatialService

        public SpatialService getSpatialService()
        Get the Geospatial service library.
        Returns:
        The GeoSpaitial library.
      • printToLog

        public void printToLog(java.lang.String message)
        Write a message to the log.
        Parameters:
        message - The message to log. The current solution name is automatically included. You must have the log level set to INFO or greater for these messages to appear in the log.
      • printToLog

        public void printToLog(java.util.logging.Level level,
                      java.lang.String message)
        Write a message to the log using a specific logging level.
        Parameters:
        level - The java.util.logging.Level to use. The message will be logged if the current logging level is equal to or greater than the specified level.
        message - The message to log. The current solution name is automatically included.
      • printToLog

        public void printToLog(java.lang.Throwable throwable)
        Log a java.lang.Throwable. If the current logging Level is INFO or greater than the following information will be written to the log: the current solution name, the Throwable's message, the Throwable's stack trace.
        Parameters:
        throwable - The java.lang.Throwable to log.
      • process

        public abstract void process(com.ibm.ia.model.Event event)
                              throws AgentException
        Entry point into agent.
        Throws:
        AgentException
      • getAgentDescriptor

        public AgentDescriptor getAgentDescriptor()
        Get the descriptor for the agent.
        Throws:
        java.lang.UnsupportedOperationException - if called outside a valid execution context
        Returns:
        The agent descriptor.
      • initializeEngineDefinition

        public com.ibm.ia.engine.runtime.EventEngineDefinition initializeEngineDefinition(java.lang.String _requiredEngineVersion,
                                                                                 java.time.ZoneId _zoneId)
      • setEventTTL

        public void setEventTTL(int ttl,
                       java.lang.String id)
      • getEventTTL

        public int getEventTTL(java.lang.String id)
      • clearEventTTL

        public void clearEventTTL(java.lang.String id)
      • setEngineTime

        public void setEngineTime(java.time.ZonedDateTime time,
                         java.lang.String id)
      • getEngineTime

        public java.time.ZonedDateTime getEngineTime(java.lang.String id)
      • clearEngineTime

        public void clearEngineTime(java.lang.String id)
      • loadRulesetArchive

        public java.io.InputStream loadRulesetArchive()
      • hasUserDefinedCookie

        public boolean hasUserDefinedCookie()
      • isThrowableIgnored

        public boolean isThrowableIgnored()
      • agentPerformsSelfMonitoring

        public boolean agentPerformsSelfMonitoring()
      • useMonitorWarning

        public boolean useMonitorWarning()
      • resolveEvent

        public com.ibm.ia.model.Event resolveEvent(EventReference ref)
      • getAgentVersion

        public Version getAgentVersion()
      • getTimeService

        public com.ibm.ia.engine.service.DefaultTimeService getTimeService()
        Specified by:
        getTimeService in interface com.ibm.ia.agent.AgentService
        Overrides:
        getTimeService in class com.ibm.ia.common.BaseComponent
      • getTimeService

        public com.ibm.ia.engine.service.DefaultTimeService getTimeService(java.lang.String _requiredEngineVersion,
                                                                  java.time.ZoneId _zoneId)
      • getRequiredEngineVersion

        public java.lang.String getRequiredEngineVersion()
        Specified by:
        getRequiredEngineVersion in interface com.ibm.ia.common.BaseComponentService
        Overrides:
        getRequiredEngineVersion in class com.ibm.ia.common.BaseComponent
      • setRequiredEngineVersion

        public void setRequiredEngineVersion(java.lang.String requiredEngineVersion)
        Specified by:
        setRequiredEngineVersion in interface com.ibm.ia.common.BaseComponentService
        Overrides:
        setRequiredEngineVersion in class com.ibm.ia.common.BaseComponent
      • getAgentProperty

        protected java.lang.String getAgentProperty(java.lang.String propName,
                                        java.lang.String agentQualifier)
      • getCalendarDuration

        protected com.ibm.ia.time.CalendarDuration getCalendarDuration(java.lang.String duration,
                                                           com.ibm.ia.time.CalendarDuration defaultDuration)
      • getFactoryServices

        protected com.ibm.rules.engine.service.EngineService[] getFactoryServices()
      • getGenericEntity

        public com.ibm.ia.common.GenericEntity getGenericEntity(com.ibm.ia.model.Entity entity)
      • getEmittedEvents

        public java.util.List<com.ibm.ia.common.GenericEvent> getEmittedEvents()
      • clearOutboundEvents

        public void clearOutboundEvents()
      • createRelationship

        public <T extends com.ibm.ia.model.Entity> com.ibm.ia.model.Relationship<T> createRelationship(T t)
        Convenience method to create Relationships
        Specified by:
        createRelationship in interface Extension
        Overrides:
        createRelationship in class com.ibm.ia.common.BaseComponent
        Parameters:
        t - Entity instance for this relationship
        Returns:
        relationship to a given entity instance
      • createRelationship

        public <T extends com.ibm.ia.model.Entity> com.ibm.ia.model.Relationship<T> createRelationship(java.lang.Class<T> entity,
                                                                                              java.lang.String key)
        Convenience method to create Relationships
        Specified by:
        createRelationship in interface Extension
        Overrides:
        createRelationship in class com.ibm.ia.common.BaseComponent
        Parameters:
        entity - entity class type for this relationship
        key - entity id for this relationship
        Returns:
        relationship to entity instance identified by type and key

© Copyright IBM 2017