Class JPPFClient

All Implemented Interfaces:
AutoCloseable, EventListener, ClientConnectionStatusListener, org.jppf.queue.QueueListener<ClientJob,ClientJob,ClientTaskBundle>

public class JPPFClient extends AbstractGenericClient
This class provides an API to submit execution requests and administration commands, and request server information data.
It has its own unique identifier, used by the nodes, to determine whether classes from the submitting application should be dynamically reloaded or not, depending on whether the uuid has changed or not.
Author:
Laurent Cohen
  • Constructor Details

    • JPPFClient

      public JPPFClient()
      Initialize this client with an automatically generated application UUID.
    • JPPFClient

      public JPPFClient(String uuid)
      Initialize this client with the specified application UUID.
      Parameters:
      uuid - the unique identifier for this local client.
    • JPPFClient

      public JPPFClient(ConnectionPoolListener... listeners)
      Initialize this client with an automatically generated application UUID.
      Parameters:
      listeners - the optional listeners to add to this JPPF client to receive notifications of new connections.
    • JPPFClient

      public JPPFClient(String uuid, ConnectionPoolListener... listeners)
      Initialize this client with the specified application UUID and new connection listeners.
      Parameters:
      uuid - the unique identifier for this local client.
      listeners - the optional listeners to add to this JPPF client to receive notifications of new connections.
    • JPPFClient

      public JPPFClient(org.jppf.utils.TypedProperties config, ConnectionPoolListener... listeners)
      Initialize this client with the specified configuration and connection listeners.
      Parameters:
      config - the JPPF configuration to use for this client.
      listeners - the optional listeners to add to this JPPF client to receive notifications of new connections.
    • JPPFClient

      public JPPFClient(String uuid, org.jppf.utils.TypedProperties config, ConnectionPoolListener... listeners)
      Initialize this client with the specified application UUID and new connection listeners.
      Parameters:
      uuid - the unique identifier for this local client.
      config - the JPPF configuration to use for this client.
      listeners - the optional listeners to add to this JPPF client to receive notifications of new connections.
  • Method Details

    • submitJob

      public List<org.jppf.node.protocol.Task<?>> submitJob(JPPFJob job)
      Deprecated.
      a job should be submittable either synchronously or asynchronously, regardless of its state. The way it is submitted is the user's choice at the time of submission, using one of submit(JPPFJob) or submitAsync(JPPFJob).
      Submit the specified job for execution.
      Parameters:
      job - the job to submit and execute.
      Returns:
      the job's results as a list of tasks if the job is blocking, or null if it is non-blocking.
    • submit

      public List<org.jppf.node.protocol.Task<?>> submit(JPPFJob job)
      Submit the specified job for execution and wait for its completion.
      Parameters:
      job - the job to submit and execute.
      Returns:
      the job's results as a list of tasks.
      Since:
      6.1
    • submitAsync

      public JPPFJob submitAsync(JPPFJob job)
      Submit the specified job asynchronously for execution, without waiting for the job to complete.
      Parameters:
      job - the job to submit and execute.
      Returns:
      the submitted job.
      Since:
      6.1
    • createJobManager

      protected JobManager createJobManager()
    • reset

      public void reset()
      Reset this client, that is, close it if necessary, reload its configuration, then open it again. If the client is already closed or reseeting, this method has no effect.
      Since:
      4.0
      See Also:
    • reset

      public void reset(org.jppf.utils.TypedProperties configuration)
      Reset this client, that is, close it if necessary, then open it again, using the specified confguration. If the client is already closed or reseeting, this method has no effect.
      Parameters:
      configuration - the configuration to initialize this client with.
      Since:
      4.0
      See Also:
    • awaitActiveConnectionPool

      public JPPFConnectionPool awaitActiveConnectionPool()
      Wait until there is at least one connection pool with at least one connection in the ACTIVE status. This is a shorthand for awaitConnectionPool(Long.MAX_VALUE, JPPFClientConnectionStatus.ACTIVE).
      Returns:
      a JPPFConnectionPool instance, or null if no pool has a connection in one of the desired statuses.
      Since:
      5.0
    • awaitWorkingConnectionPool

      public JPPFConnectionPool awaitWorkingConnectionPool()
      Wait until there is at least one connection pool with at least one connection in the ACTIVE or EXECUTING status. This is a shorthand for awaitConnectionPool(Long.MAX_VALUE, JPPFClientConnectionStatus.ACTIVE, JPPFClientConnectionStatus.EXECUTING).
      Returns:
      a JPPFConnectionPool instance, or null if no pool has a connection in one of the desired statuses.
      Since:
      5.0
    • awaitConnectionPool

      public JPPFConnectionPool awaitConnectionPool(JPPFClientConnectionStatus... statuses)
      Wait until there is at least one connection pool with at least one connection in one of the specified statuses. This is a shorthand for awaitConnectionPool(Long.MAX_VALUE, statuses).
      Parameters:
      statuses - the possible statuses of the connections in the pools to wait for.
      Returns:
      a JPPFConnectionPool instance, or null if no pool has a connection in one of the desired statuses.
      Since:
      5.0
    • awaitConnectionPool

      public JPPFConnectionPool awaitConnectionPool(long timeout, JPPFClientConnectionStatus... statuses)
      Wait until at least one connection pool with at least one connection in one of the specified statuses, or until the specified timeout to expire, whichever happens first.
      Parameters:
      timeout - the maximum time to wait, in milliseconds. A value of zero means an infinite timeout.
      statuses - the possible statuses of the connections in the pools to wait for.
      Returns:
      a JPPFConnectionPool instance, or null if no pool has a connection in one of the desired statuses.
      Since:
      5.0
    • awaitWorkingConnectionPools

      public List<JPPFConnectionPool> awaitWorkingConnectionPools()
      Wait until there is at least one connection pool with at least one connection in the ACTIVE or EXECUTING status. This is a shorthand for awaitConnectionPools(Long.MAX_VALUE, JPPFClientConnectionStatus.ACTIVE, JPPFClientConnectionStatus.EXECUTING).
      Returns:
      a list of JPPFConnectionPool instances, possibly empty but never null.
      Since:
      5.1
    • awaitWorkingConnectionPools

      public List<JPPFConnectionPool> awaitWorkingConnectionPools(long timeout)
      Wait until there is at least one connection pool with at least one connection in the ACTIVE or EXECUTING status, or the specified tiemoput expires, whichever happens first. This is a shorthand for awaitConnectionPools(tiemout, JPPFClientConnectionStatus.ACTIVE, JPPFClientConnectionStatus.EXECUTING).
      Parameters:
      timeout - the maximum time to wait, in milliseconds. A value of zero means an infinite timeout.
      Returns:
      a list of JPPFConnectionPool instances, possibly empty but never null.
      Since:
      5.1
    • awaitConnectionPools

      public List<JPPFConnectionPool> awaitConnectionPools(long timeout, JPPFClientConnectionStatus... statuses)
      Wait until at least one connection pool with at least one connection in one of the specified statuses, or until the specified timeout to expire, whichever happens first.
      Parameters:
      timeout - the maximum time to wait, in milliseconds. A value of zero means an infinite timeout.
      statuses - the possible statuses of the connections in the pools to wait for.
      Returns:
      a list of JPPFConnectionPool instances, possibly empty but never null.
      Since:
      5.0
    • awaitConnectionPools

      public List<JPPFConnectionPool> awaitConnectionPools(org.jppf.utils.ComparisonOperator operator, int expectedConnections, long timeout, JPPFClientConnectionStatus... statuses)
      Wait until there is at least one connection pool where the number of connections with the specified statuses satisfy the specified condition, or until the specified timeout expires, whichever happens first.
      Parameters:
      operator - the condition on the number of connections to wait for. If null, it is assumed to be Operator.EQUAL.
      expectedConnections - the expected number of connections to wait for.
      timeout - the maximum time to wait, in milliseconds. A value of zero means an infinite timeout.
      statuses - the possible statuses of the connections in the pools to wait for.
      Returns:
      a list of JPPFConnectionPool instances, possibly empty but never null.
      Since:
      5.0
    • awaitConnectionPools

      public List<JPPFConnectionPool> awaitConnectionPools(org.jppf.utils.ComparisonOperator poolOperator, int expectedPools, org.jppf.utils.ComparisonOperator connectionOperator, int expectedConnections, long timeout, JPPFClientConnectionStatus... statuses)
      Wait until at least the specified expected connection pools satisfy the condition where the number of connections with the specified statuses satisfy the specified connection operator, or until the specified timeout expires, whichever happens first.

      As an example, to wait for at least 2 pools having each at least one ACTIVE connection, with a timeout of 5 seconds, one would use:

       JPPFClient client = new JPPFClient();
       client.awaitConnectionPools(Operator.AT_LEAST, 2, Operator.AT_LEAST, 1,
         5000L, JPPFClientConnectionStatus.ACTIVE);
       
      Parameters:
      poolOperator - the condition on the number of expected pools to wait for. If null, it is assumed to be Operator.EQUAL.
      expectedPools - the expected number of pools to wait for.
      connectionOperator - the condition on the number of connections to wait for. If null, it is assumed to be Operator.EQUAL.
      expectedConnections - the expected number of connections to wait for.
      timeout - the maximum time to wait, in milliseconds. A value of zero means an infinite timeout.
      statuses - the possible statuses of the connections in the pools to wait for.
      Returns:
      a list of JPPFConnectionPool instances, possibly empty but never null.
      Since:
      6.0
    • awaitConnectionPools

      public List<JPPFConnectionPool> awaitConnectionPools(long timeout, ConnectionPoolFilter<JPPFConnectionPool> filter)
      Wait until there is at least one connection pool where at least one connections passes the specified filter, or until the specified timeout expires, whichever happens first.
      Parameters:
      timeout - the maximum time to wait, in milliseconds. A value of zero means an infinite timeout.
      filter - an implementation of the ConnectionPoolFilter interface. A null value is interpreted as no filter (all pools are accepted).
      Returns:
      a list of JPPFConnectionPool instances, possibly empty but never null.
      Since:
      5.0
    • close

      public void close()
      Description copied from class: AbstractJPPFClient
      Close this client and release all the resources it is using.
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class AbstractGenericClient
    • removeDriverDiscovery

      public void removeDriverDiscovery(org.jppf.discovery.ClientDriverDiscovery discovery)
      Remove a custom driver discovery mechanism from those already registered.
      Parameters:
      discovery - the driver discovery to remove.
    • getLoadBalancerSettings

      public org.jppf.load.balancer.LoadBalancingInformation getLoadBalancerSettings()
      Get the current load-balancer settings.
      Returns:
      a LoadBalancingInformation instance, which encapsulates a load-balancing alfgorithm name, along with its parameters.
      Since:
      5.2.7
    • setLoadBalancerSettings

      public void setLoadBalancerSettings(String algorithm, Properties parameters) throws Exception
      Change the load balancer settings.
      Parameters:
      algorithm - the name of load-balancing alogrithm to use.
      parameters - the algorithm's parameters, if any. The parmeter names are assumed no to be prefixed.
      Throws:
      Exception - if any error occurs or if the algorithm name is null or not known.
      Since:
      5.2.7
    • getBundlerFactory

      public org.jppf.load.balancer.spi.JPPFBundlerFactory getBundlerFactory()
      Get the factory that creates load-balancer instances.
      Returns:
      an istance of JPPFBundlerFactory.
    • nbIdleCOnnections

      public int nbIdleCOnnections()
      Returns:
      the number of idle connections in this client.
    • getDefaultPolicy

      public org.jppf.node.policy.ExecutionPolicy getDefaultPolicy()
      Get the default server-side job execution policy.
      Returns:
      an ExecutionPolicy, or null if none was specified.
    • setDefaultPolicy

      public void setDefaultPolicy(org.jppf.node.policy.ExecutionPolicy defaultPolicy)
      Set the default server-side job execution policy.
      Parameters:
      defaultPolicy - the execution policy to set as default, may be null.
    • getDefaultClientPolicy

      public org.jppf.node.policy.ExecutionPolicy getDefaultClientPolicy()
      Get the default client-side job execution policy.
      Returns:
      an ExecutionPolicy, or null if none was specified.
    • setDefaultClientPolicy

      public void setDefaultClientPolicy(org.jppf.node.policy.ExecutionPolicy defaultClientPolicy)
      Set the default client-side job execution policy.
      Parameters:
      defaultClientPolicy - the execution policy to set as default, may be null.
    • getQueuedJobs

      public List<JPPFJob> getQueuedJobs()
      Get the list of currently queued jobs.
      Returns:
      a list of JPPFJob instances, possibly empty.
    • getQueuedJobs

      public List<JPPFJob> getQueuedJobs(org.jppf.job.JobSelector selector)
      Get a list of currently queued jobs, filtered by a JobSelector.
      Parameters:
      selector - a job filter to apply. May be null, in which case all queued jobs are returned.
      Returns:
      a list of JPPFJob instances that satisfy the provided job selector, possibly empty.
    • getQueuedJobsCount

      public int getQueuedJobsCount()
      Get the current number of queued jobs.
      Returns:
      the current queued jobs count as an int.
    • getQueuedJobsCount

      public int getQueuedJobsCount(org.jppf.job.JobSelector selector)
      Get the current number of jobs that satisfy a job selector.
      Parameters:
      selector - a job filter to apply. May be null, in which case the count of all queued jobs is returned.
      Returns:
      the number of queued jobs that satisfy the filter.