com.waveset.provision
Class FetchContext

java.lang.Object
  extended bycom.waveset.provision.ThreadContext
      extended bycom.waveset.provision.FetchContext
Direct Known Subclasses:
ResourcePasswordContext

public class FetchContext
extends ThreadContext

A class holding the runtime state for a resource account fetch used to assemble all of the resource account attribute for a Waveset user.


Field Summary
static java.lang.String code_id
           
 
Fields inherited from class com.waveset.provision.ThreadContext
trace
 
Constructor Summary
FetchContext(Provisioner p, ProvisioningOptions options)
           
 
Method Summary
 void buildResourceOps()
          Build a base list of "resource operation" objects for each account assigned to the user.
 void doFetch(ResourceOp op, int thread)
          This is the inner implementation of the fetch operation.
 int getDesiredThreads()
          Calculate the optimum number of threads that could be launched to perform the ResourceOps in parallel.
 ResourceOp getNextOp()
          Return the next operation that a thread can perform.
 java.util.List getOps()
          Return the list of ResourceOps.
 java.util.List getResults()
          Once all the threads have finished, iterate through the internal ResourceOp objects, and return a list of the ResourceResult objects that were left behind.
 void init()
          Initialize all processing state.
 boolean isFinished(int thread)
          Returns true once all operations have been performed.
 void prepare()
          Make any last minute preparations before launching.
 void processOp(ResourceOp op, int thread)
          Called by each thread after it has obtained an operation to perform.
 
Methods inherited from class com.waveset.provision.ThreadContext
buildResourceUser, buildResourceUser, checkAdapters, generateIdentities, getAdministratorName, getExplicitIdentity, getOp, getOptions, getProvisioner, getUser, getUserName, launchThreads, normalizeResourceInfos, overrideResourceAttributes, println, setTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values
Constructor Detail

FetchContext

public FetchContext(Provisioner p,
                    ProvisioningOptions options)
Method Detail

getOps

public java.util.List getOps()
Description copied from class: ThreadContext
Return the list of ResourceOps. Used internally by some of the utility methods.

Specified by:
getOps in class ThreadContext

init

public void init()
Initialize all processing state.


getResults

public java.util.List getResults()
Once all the threads have finished, iterate through the internal ResourceOp objects, and return a list of the ResourceResult objects that were left behind.


prepare

public void prepare()
             throws WavesetException
Make any last minute preparations before launching.

Specified by:
prepare in class ThreadContext
Throws:
WavesetException

getDesiredThreads

public int getDesiredThreads()
Calculate the optimum number of threads that could be launched to perform the ResourceOps in parallel. This number will be used by the Provisioner in determining how many threads to launch. We may end up with substantially fewer threads, here we're just giving the ideal number.

Specified by:
getDesiredThreads in class ThreadContext

isFinished

public boolean isFinished(int thread)
Returns true once all operations have been performed. This is a signal to the thread that it can terminate.

The thread number is passed here so we can selectively decide to let threads expire even though we're not really done with processing. This might happen if we launched 10 threads to do a bunch of random things in parallel, but we're now down to 2 that have to iterate through 2 ordered lists. Since the other threads have nothing to do, we can let the die.

Specified by:
isFinished in class ThreadContext

getNextOp

public ResourceOp getNextOp()
Return the next operation that a thread can perform. This needs to be synchronized since it will be called by multiple threads. If null is returned, that doesn't necessarily mean we're finished, we may be waititng for dependent operations to finish.

Specified by:
getNextOp in class ThreadContext

processOp

public void processOp(ResourceOp op,
                      int thread)
               throws WavesetException
Called by each thread after it has obtained an operation to perform. This method must not be synchronized, all the state we need should be in the provided ResourceOp object.

Specified by:
processOp in class ThreadContext
Throws:
WavesetException

buildResourceOps

public void buildResourceOps()
                      throws WavesetException
Build a base list of "resource operation" objects for each account assigned to the user. This may be filtered later depending on other constraints.

Throws:
WavesetException

doFetch

public void doFetch(ResourceOp op,
                    int thread)
             throws WavesetException
This is the inner implementation of the fetch operation. It will be called by each fetch thread as they iterate over the op list.

This method must not be synchronized, all state is maintained in the ResourceOp. We're allowed to touch the WSUser object but the only modifications should be made in the ResourceInfo that is associated with this resource.

Throws:
WavesetException