FileDocCategorySizeDatePackage
Consumer.javaAPI DocExample3407Thu May 23 09:32:50 BST 2002 sample.loading

Consumer

public class Consumer extends Worker implements MBeanRegistration
This class pulls WorkUnit instances from a Queue and performs a certain amount of "work", specified by workFactor.

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

    
      
    
public Consumer(sample.standard.Queue queue)

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

        super(inputQueue, 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.addConsumer();
        //**********
        // 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 || _queue.isEndOfInput())) {
            while (_suspended) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {}
            }
            WorkUnit unit = (WorkUnit)_queue.remove();
            // Burn some cycles...
            calculatePrimes(_workFactor);
            _numberOfUnitsProcessed++;
        }
        _queue.removeConsumer();