FileDocCategorySizeDatePackage
Supplier.javaAPI DocExample3443Thu May 23 09:32:50 BST 2002 sample.loading

Supplier

public class Supplier extends Worker implements MBeanRegistration
Represents the supplier component of the sample application. Does some work, and places the results into a queue. Implemented as a standard MBean.

Fields Summary
public static final String
ROLE
private static final int
DEFAULT_WORK_FACTOR
Constructors Summary
public Supplier()

    
      
    
public Supplier(sample.standard.Queue queue)

        this(queue, DEFAULT_WORK_FACTOR);
    
public Supplier(sample.standard.Queue queue, int workFactor)

        super(queue, workFactor);
    
Methods Summary
public voidpostDeregister()
Allows the MBean to perform any operations needed after having been de-registered in the MBean server.

        // do nothing
    
public voidpostRegister(java.lang.Boolean registrationDone)
Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.

param
registrationDone Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.

        // do nothing
    
public voidpreDeregister()
Allows the MBean to perform any operations it needs before being de-registered by the MBean server.

exception
java.langException This exception should be caught by the MBean server and re-thrown as an MBeanRegistrationException.

        // do nothing
    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
Allows the MBean to perform any operations it needs before being registered in the MBean server. If the name of the MBean is not specified, the MBean can provide a name for its registration. If any exception is raised, the MBean will not be registered in the MBean server.

param
server The MBean server in which the MBean will be registered.
param
name The object name of the MBean.
return
The name of the MBean registered.
exception
java.lang.Exception This exception should be caught by the MBean server and re-thrown as an MBeanRegistrationException.

        ObjectName objName = new ObjectName(OBJECT_NAME + ",role=" + ROLE);
        return objName;
    
public voidrun()

        _queue.addSupplier();
        //**********
        // This is where the "work" takes place. In a real-world
        /// application that uses this pattern, this logic would
        /// be replaced by the real application logic.
        //**********
        while (!_stopCalled) {
            while (_suspended) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {}
            }
            // Burn some cycles...
            calculatePrimes(_workFactor);
            // Now place a WorkUnit in the Queue
            _queue.add(new WorkUnit());
            _numberOfUnitsProcessed++;
        }
        _queue.removeSupplier();