sofya.ed.structural.processors
Class BlockSequenceProcessingStrategy

java.lang.Object
  extended by sofya.ed.structural.processors.AbstractProcessingStrategy
      extended by sofya.ed.structural.processors.AbstractSocketProcessingStrategy
          extended by sofya.ed.structural.processors.BlockSequenceProcessingStrategy
All Implemented Interfaces:
ActiveComponent, BlockInstrumentationStrategy, SocketProcessingStrategy

public class BlockSequenceProcessingStrategy
extends AbstractSocketProcessingStrategy
implements BlockInstrumentationStrategy

Processing strategy to receive basic block sequence probes and dispatch basic block sequence events.

Version:
08/04/2006
Author:
Alex Kinneer

Field Summary
protected static long pendingTimeStamp
          Last timestamp that forced a synchronization, used when the subject is an event dispatcher.
protected static java.lang.Object timeLock
          Synchronizes access to pendingTimeStamp and controls notifications between threads.
 
Fields inherited from class sofya.ed.structural.processors.AbstractSocketProcessingStrategy
isSbjDispatcher, PREEMPTIVE, traceLock
 
Fields inherited from class sofya.ed.structural.processors.AbstractProcessingStrategy
instMode, sbjout, stderr, stdout
 
Constructor Summary
BlockSequenceProcessingStrategy()
          Creates a new instance of the processing strategy.
 
Method Summary
 void addEventListener(BlockEventListener listener)
          Registers a listener for observable events.
 boolean areCallBlocksActive()
          Reports whether call blocks are selected.
 boolean areCodeBlocksActive()
          Reports whether general basic blocks are selected; general basic blocks are any basic blocks corresponding to actual program code other than method call blocks.
 boolean areEntryBlocksActive()
          Reports whether entry blocks are selected.
 boolean areExitBlocksActive()
          Reports whether exit blocks are selected.
 java.util.List configure(java.util.List params)
          Configures this component from command line parameters.
 void dispatcherStarting()
          Message sent by the event dispatcher to indicate that it is about to start receiving data to publish its event stream.
 void dispatcherStopped()
          Message sent by the event dispatcher to indicate that it has stopped receiving data used to publish its event stream.
 void doHandshake(java.net.Socket sbjSocket)
          Executes the handshake procedure with the socket probe.
 int getTypeFlags()
          Gets the bitmask corresponding to the types of basic blocks currently selected.
 boolean isReady()
          Reports whether this component is ready for the event dispatcher to begin dispatching events.
 void processProbes(java.net.Socket sbjSocket, ControlData cntrl)
          The standard trace processing loop, used for all subjects except other event dispatchers.
 void processProbesSynchronized(java.net.Socket sbjSocket, ControlData cntrl)
          The synchronized trace processing loop.
 void register(EventDispatcherConfiguration edConfig)
          Registers this component with the event dispatcher.
 void release()
          Notifies this component that its current lifecycle has expired and that it should commit any stored state and release resources.
 void removeEventListener(BlockEventListener listener)
          Unregisters a listener for observable events.
 void reset()
          Notifies this component to clear its configuration and reset any internal state.
 void setCallBlocksActive(boolean enable)
          Sets whether call blocks are selected.
 void setCodeBlocksActive(boolean enable)
          Sets whether general basic blocks are selected; general basic blocks are any basic blocks corresponding to actual program code other than method call blocks.
 void setEntryBlocksActive(boolean enable)
          Sets whether entry blocks are selected.
 void setExitBlocksActive(boolean enable)
          Sets whether exit blocks are selected.
 
Methods inherited from class sofya.ed.structural.processors.AbstractSocketProcessingStrategy
openSignalSocket, parseMethodSignature
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pendingTimeStamp

protected static volatile long pendingTimeStamp
Last timestamp that forced a synchronization, used when the subject is an event dispatcher.


timeLock

protected static java.lang.Object timeLock
Synchronizes access to pendingTimeStamp and controls notifications between threads.

Constructor Detail

BlockSequenceProcessingStrategy

public BlockSequenceProcessingStrategy()
Creates a new instance of the processing strategy.

Method Detail

addEventListener

public void addEventListener(BlockEventListener listener)
Registers a listener for observable events.

Parameters:
listener - Observer that wishes to receive basic block events from the event dispatcher.

removeEventListener

public void removeEventListener(BlockEventListener listener)
Unregisters a listener for observable events.

Parameters:
listener - Object that no longer wishes to receive basic block events from the event dispatcher.

register

public void register(EventDispatcherConfiguration edConfig)
Description copied from class: AbstractProcessingStrategy

Registers this component with the event dispatcher.

Specified by:
register in interface ActiveComponent
Overrides:
register in class AbstractSocketProcessingStrategy
Parameters:
edConfig - The current configuration of system global resources and settings that the component will use as appropriate.

configure

public java.util.List configure(java.util.List params)
Description copied from interface: ActiveComponent

Configures this component from command line parameters.

This method provides a component the opportunity to define and process command line parameters required to configure itself. Components participate in a processing chain, initiated in Sofya-provided event dispatchers by calling this method on the processing strategy. The processing strategies provided by Sofya in turn invoke this method on any listeners implementing this interface.

Specified by:
configure in interface ActiveComponent
Overrides:
configure in class AbstractSocketProcessingStrategy
Parameters:
params - A list of command line tokens that have not yet been processed by any previous components.
Returns:
The list of parameters, with any recognized parameters and associated values removed. This enables the chaining of parameter processing.

reset

public void reset()
Description copied from interface: ActiveComponent

Notifies this component to clear its configuration and reset any internal state.

Calls to this method are chained similary to the ActiveComponent.configure(java.util.List) method. This method is invoked by the event dispatcher prior to reconfiguration. Normally it should be used to clear any configuration state to avoid using stale values.

Specified by:
reset in interface ActiveComponent
Overrides:
reset in class AbstractSocketProcessingStrategy

isReady

public boolean isReady()
Description copied from interface: ActiveComponent

Reports whether this component is ready for the event dispatcher to begin dispatching events.

Calls to this method are chained similarly to the ActiveComponent.configure(java.util.List) method. The event dispatcher will fail with an error if a client invokes ProgramEventDispatcher.startDispatcher() when any attached component returns false from this method.

Specified by:
isReady in interface ActiveComponent
Returns:
true if this component is ready for the event dispatcher to begin dispatching events, false otherwise.

release

public void release()
Description copied from interface: ActiveComponent

Notifies this component that its current lifecycle has expired and that it should commit any stored state and release resources.

Calls to this method are chained similary to the ActiveComponent.configure(java.util.List) method. This method is invoked directly by a client of the event dispatcher. Normally, it should be used to release any resources that were required to persist over multiple runs of the event dispatcher.

Specified by:
release in interface ActiveComponent
Overrides:
release in class AbstractSocketProcessingStrategy

dispatcherStarting

public void dispatcherStarting()
Description copied from interface: SocketProcessingStrategy
Message sent by the event dispatcher to indicate that it is about to start receiving data to publish its event stream.

This message provides the processing strategy an opportunity to take some action prior to handling the event stream, such as issuing a message to listeners.

Specified by:
dispatcherStarting in interface SocketProcessingStrategy

dispatcherStopped

public void dispatcherStopped()
Description copied from interface: SocketProcessingStrategy
Message sent by the event dispatcher to indicate that it has stopped receiving data used to publish its event stream.

This message provides the processing strategy an opportunity to take some action after handling the event stream, such as issuing a message to listeners.

Specified by:
dispatcherStopped in interface SocketProcessingStrategy

doHandshake

public void doHandshake(java.net.Socket sbjSocket)
                 throws java.io.IOException,
                        AbstractEventDispatcher.ExecException
Description copied from interface: SocketProcessingStrategy
Executes the handshake procedure with the socket probe.

This method should check whether the type of instrumentation indicated by the socket probe is appropriate for this processing strategy. If it is not, an error response should be sent to the socket probe and an exception thrown. Otherwise, the integer code for the form of instrumentation to be processed should be returned.

Specified by:
doHandshake in interface SocketProcessingStrategy
Parameters:
sbjSocket - Main communications socket which is connected to the socket probe.
Throws:
java.io.IOException - If there is any error communicating through the socket.
AbstractEventDispatcher.ExecException - If the instrumentation in the subject is not appropriate for this type of filter.

processProbes

public void processProbes(java.net.Socket sbjSocket,
                          ControlData cntrl)
Description copied from interface: SocketProcessingStrategy
The standard trace processing loop, used for all subjects except other event dispatchers.

The run loop waits for the subject to negotiate a socket connection and then begins processing trace messages until the socket stream is closed. If the subject is not instrumented, this loop will be killed while waiting for the subject to connect when the main thread calls ProgramEventDispatcher.stopServer().

A standard trace processing loop is provided distinct from the synchronized version so that the cost of synchronization is not incurred for all subjects. This also avoids complications related to determining when to strip timestamps from trace messages. The cost of this implementation is that you must remember to update both this method and SocketProcessingStrategy.processProbesSynchronized(java.net.Socket, sofya.ed.structural.ControlData) when making changes to how trace messages are processed.

Specified by:
processProbes in interface SocketProcessingStrategy

processProbesSynchronized

public void processProbesSynchronized(java.net.Socket sbjSocket,
                                      ControlData cntrl)
Description copied from interface: SocketProcessingStrategy
The synchronized trace processing loop.

The processing performed by this run loop should be functionally equivalent to that of SocketProcessingStrategy.processProbes(java.net.Socket, sofya.ed.structural.ControlData). The only difference is that this loop should synchronize access to the listeners.

Note: This method is only expected to synchronize two threads. The event dispatcher will never execute this method from more than two threads, as there is no reason to do so.

Specified by:
processProbesSynchronized in interface SocketProcessingStrategy

areCodeBlocksActive

public boolean areCodeBlocksActive()
Description copied from interface: BlockInstrumentationStrategy
Reports whether general basic blocks are selected; general basic blocks are any basic blocks corresponding to actual program code other than method call blocks.

Specified by:
areCodeBlocksActive in interface BlockInstrumentationStrategy
Returns:
true if general basic blocks are selected, false otherwise.

setCodeBlocksActive

public void setCodeBlocksActive(boolean enable)
Description copied from interface: BlockInstrumentationStrategy
Sets whether general basic blocks are selected; general basic blocks are any basic blocks corresponding to actual program code other than method call blocks.

Specified by:
setCodeBlocksActive in interface BlockInstrumentationStrategy
Parameters:
enable - true to select general basic blocks, false to ignore.

areEntryBlocksActive

public boolean areEntryBlocksActive()
Description copied from interface: BlockInstrumentationStrategy
Reports whether entry blocks are selected.

Specified by:
areEntryBlocksActive in interface BlockInstrumentationStrategy
Returns:
true if entry blocks are selected, false otherwise.

setEntryBlocksActive

public void setEntryBlocksActive(boolean enable)
Description copied from interface: BlockInstrumentationStrategy
Sets whether entry blocks are selected.

Specified by:
setEntryBlocksActive in interface BlockInstrumentationStrategy
Parameters:
enable - true to select entry blocks, false to ignore.

areExitBlocksActive

public boolean areExitBlocksActive()
Description copied from interface: BlockInstrumentationStrategy
Reports whether exit blocks are selected.

Specified by:
areExitBlocksActive in interface BlockInstrumentationStrategy
Returns:
true if exit blocks are selected, false otherwise.

setExitBlocksActive

public void setExitBlocksActive(boolean enable)
Description copied from interface: BlockInstrumentationStrategy
Sets whether exit blocks are selected.

Specified by:
setExitBlocksActive in interface BlockInstrumentationStrategy
Parameters:
enable - true to select exit blocks, false to ignore.

areCallBlocksActive

public boolean areCallBlocksActive()
Description copied from interface: BlockInstrumentationStrategy
Reports whether call blocks are selected.

Specified by:
areCallBlocksActive in interface BlockInstrumentationStrategy
Returns:
true if call blocks are selected, false otherwise.

setCallBlocksActive

public void setCallBlocksActive(boolean enable)
Description copied from interface: BlockInstrumentationStrategy
Sets whether call blocks are selected.

Specified by:
setCallBlocksActive in interface BlockInstrumentationStrategy
Parameters:
enable - true to select call blocks, false to ignore.

getTypeFlags

public int getTypeFlags()
Description copied from interface: BlockInstrumentationStrategy
Gets the bitmask corresponding to the types of basic blocks currently selected.

Used for communicating configuration information to certain other components. To be phased out at a future date.

Specified by:
getTypeFlags in interface BlockInstrumentationStrategy
Returns:
The bitmask indicating which basic block types have been selected in this configuration.