sofya.ed.structural.processors
Class AbstractSocketProcessingStrategy

java.lang.Object
  extended by sofya.ed.structural.processors.AbstractProcessingStrategy
      extended by sofya.ed.structural.processors.AbstractSocketProcessingStrategy
All Implemented Interfaces:
ActiveComponent, SocketProcessingStrategy
Direct Known Subclasses:
BlockCoverageProcessingStrategy, BlockSequenceProcessingStrategy, BranchCoverageProcessingStrategy, BranchSequenceProcessingStrategy

public abstract class AbstractSocketProcessingStrategy
extends AbstractProcessingStrategy
implements SocketProcessingStrategy

Base class for strategies to receive and process probes for a program event dispatcher.

Version:
08/04/2006
Author:
Alex Kinneer

Field Summary
protected static boolean isSbjDispatcher
          Local copy of the flag indicating whether the subject is itself an event dispatcher.
protected static boolean PREEMPTIVE
          Conditional compilation flag indicating whether the JVM is a preemptive JVM.
protected static java.lang.Object traceLock
          Lock used to synchronize access to the listener or listeners.
 
Fields inherited from class sofya.ed.structural.processors.AbstractProcessingStrategy
instMode, sbjout, stderr, stdout
 
Constructor Summary
protected AbstractSocketProcessingStrategy()
           
 
Method Summary
 java.util.List configure(java.util.List parameters)
          Configures this component from command line parameters.
protected  java.net.Socket openSignalSocket(java.net.Socket msgSocket)
          Connects the signal socket used to allow basic communication with the subject's SocketProbe.
protected  java.lang.String parseMethodSignature(java.io.DataInputStream in, byte[] buffer)
          Reads the method signature portion of a trace message from the socket and parses it into its class name and fully qualified method name.
 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 reset()
          Notifies this component to clear its configuration and reset any internal state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sofya.ed.structural.SocketProcessingStrategy
dispatcherStarting, dispatcherStopped, doHandshake, processProbes, processProbesSynchronized
 
Methods inherited from interface sofya.ed.structural.ActiveComponent
isReady
 

Field Detail

isSbjDispatcher

protected static boolean isSbjDispatcher
Local copy of the flag indicating whether the subject is itself an event dispatcher.


traceLock

protected static java.lang.Object traceLock
Lock used to synchronize access to the listener or listeners.


PREEMPTIVE

protected static final boolean PREEMPTIVE
Conditional compilation flag indicating whether the JVM is a preemptive JVM.

See Also:
Constant Field Values
Constructor Detail

AbstractSocketProcessingStrategy

protected AbstractSocketProcessingStrategy()
Method Detail

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 AbstractProcessingStrategy
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 parameters)
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
Parameters:
parameters - 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

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

parseMethodSignature

protected java.lang.String parseMethodSignature(java.io.DataInputStream in,
                                                byte[] buffer)
                                         throws java.io.IOException,
                                                AbstractEventDispatcher.ExecException
Reads the method signature portion of a trace message from the socket and parses it into its class name and fully qualified method name.

All of the outputs of this method are side effects.

Parameters:
in - Input stream which is connected to the trace message socket.
buffer - Byte buffer used to hold the signature string when it is read from the socket and from which the parsing is performed. If the signature string exceeds the size of this buffer, the method will still succeed, but will be considerably slower since it must process the signature in chunks. A reasonably large buffer is recommended.
Throws:
AbstractEventDispatcher.ExecException - If the signature string is improperly encoded and cannot be parsed.
java.io.IOException - If there is any other error reading from the socket.

openSignalSocket

protected java.net.Socket openSignalSocket(java.net.Socket msgSocket)
                                    throws java.io.IOException
Connects the signal socket used to allow basic communication with the subject's SocketProbe.

This method attempts to find a free port and bind a server socket to it. It then writes the chosen port onto the main socket connection for the SocketProbe to read and waits for the incoming connection. Once the connection is established, it returns the associated socket and no further data is written to the main socket connection.

Note: Coverage processing strategies do not use the signal socket, however we still negotiate the connection so the SocketProbe doesn't get confused. The signal socket is intended for use by sequence processing strategies.

Parameters:
msgSocket - The main socket which will be used for trace messages, which should be connected before calling this method.
Returns:
A socket representing the signal connection.
Throws:
java.io.IOException - If an open port for the signal socket cannot be found, there is an error connecting the socket, or there is an error attempting to transmit the port number to the SocketProbe.