org.jppf.server.protocol
Class AbstractLocation<T>

java.lang.Object
  extended by org.jppf.server.protocol.AbstractLocation<T>
Type Parameters:
T - the type of this location.
All Implemented Interfaces:
Serializable, Location<T>
Direct Known Subclasses:
FileLocation, MemoryLocation, URLLocation

public abstract class AbstractLocation<T>
extends Object
implements Serializable, Location<T>

Instances of this class represent the location of an artifact, generally a file or the data found at a url.

Author:
Laurent Cohen
See Also:
Serialized Form

Field Summary
protected  boolean eventsEnabled
          Boolean flag that determines if at least one listener is registered.
protected  List<LocationEventListener> listeners
          The list of listeners to this location.
protected  T path
          The path for this location.
 
Constructor Summary
AbstractLocation(T path)
          Initialize this location with the specified type and path.
 
Method Summary
 void addLocationEventListener(LocationEventListener listener)
          Add a listener to the list of location event listeners for this location.
 void copyTo(Location location)
          Copy the content at this location to another location.
protected  void fireLocationEvent(int n)
          Notify all listeners that a data transfer has occurred.
 T getPath()
          Return the path to this location.
 void removeLocationEventListener(LocationEventListener listener)
          Remove a listener from the list of location event listeners for this location.
 byte[] toByteArray()
          Get the content at this location as an array of bytes.
 String toString()
          Get a string representation of this location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jppf.server.protocol.Location
getInputStream, getOutputStream, size
 

Field Detail

path

protected T path
The path for this location.


listeners

protected List<LocationEventListener> listeners
The list of listeners to this location.


eventsEnabled

protected boolean eventsEnabled
Boolean flag that determines if at least one listener is registered. Used to minimize the overhead of sending events if there is no listener.

Constructor Detail

AbstractLocation

public AbstractLocation(T path)
Initialize this location with the specified type and path.

Parameters:
path - the path for this location.
Method Detail

getPath

public T getPath()
Return the path to this location.

Specified by:
getPath in interface Location<T>
Returns:
the path.
See Also:
Location.getPath()

copyTo

public void copyTo(Location location)
            throws Exception
Copy the content at this location to another location.

Specified by:
copyTo in interface Location<T>
Parameters:
location - the location to copy to.
Throws:
Exception - if an I/O error occurs.
See Also:
Location.copyTo(org.jppf.server.protocol.Location)

toByteArray

public byte[] toByteArray()
                   throws Exception
Get the content at this location as an array of bytes.

Specified by:
toByteArray in interface Location<T>
Returns:
a byte array.
Throws:
Exception - if an I/O error occurs.
See Also:
Location.toByteArray()

toString

public String toString()
Get a string representation of this location.

Overrides:
toString in class Object
Returns:
this location as a string.
See Also:
Object.toString()

addLocationEventListener

public void addLocationEventListener(LocationEventListener listener)
Add a listener to the list of location event listeners for this location.

Specified by:
addLocationEventListener in interface Location<T>
Parameters:
listener - the listener to add to the list.
Throws:
NullPointerException - if the listener object is null.
See Also:
Location.addLocationEventListener(org.jppf.server.protocol.LocationEventListener)

removeLocationEventListener

public void removeLocationEventListener(LocationEventListener listener)
Remove a listener from the list of location event listeners for this location.

Specified by:
removeLocationEventListener in interface Location<T>
Parameters:
listener - the listener to remove from the list.
Throws:
NullPointerException - if the listener object is null.
See Also:
Location.removeLocationEventListener(org.jppf.server.protocol.LocationEventListener)

fireLocationEvent

protected void fireLocationEvent(int n)
Notify all listeners that a data transfer has occurred.

Parameters:
n - - the size of the data that was transferred.


Copyright © 2005-2010 JPPF Team.