cz.cuni.jagrlib
Class BasicChannel

java.lang.Object
  extended by cz.cuni.jagrlib.BasicChannel
All Implemented Interfaces:
Channel

public class BasicChannel
extends java.lang.Object
implements Channel

Simple Channel implementation. HashSets are used for left- and right-side connections.

Since:
0.01
See Also:
BasicChannel.java

Field Summary
protected  java.lang.Object leftInterface
          Interface object for the left-side (called by right-side Piece[s]).
protected  java.lang.String leftInterfaceName
          Fully-qualified interface name of the left side (called from the right side).
protected  java.util.HashSet<Plug> leftSet
          Set of Plugs connected to the left side.
protected  java.lang.Object rightInterface
          Interface object for the right-side (called by left-side Piece[s]).
protected  java.lang.String rightInterfaceName
          Fully-qualified interface name of the right side (called from the left side).
protected  java.util.HashSet<Plug> rightSet
          Set of Plugs connected to the right side.
 
Constructor Summary
BasicChannel(java.lang.String _leftInterfaceName, java.lang.String _rightInterfaceName)
          Initializing constructor.
 
Method Summary
 void connectAnti(Plug newPlug, Plug antiPlug)
          Connects a new Plug to the opposite Channel-side.
 void connectLeft(Plug newPlug)
          Connects a new Plug to the left Channel-side.
 void connectPro(Plug newPlug, Plug proPlug)
          Connects a new Plug to the same Channel-side.
 void connectRight(Plug newPlug)
          Connects a new Plug to the right Channel-side.
 void disconnect(Plug oldPlug)
          Disconnects the old Plug from the Channel.
 void disconnectAll()
          Disconnects all Plugs from the Channel.
 Plug[] getAnti(Plug antiPlug)
          Returns the array of opposite-side objects (Plugs).
 java.lang.Object getInterface(Plug caller)
          Returns the interface object of the given Channel-side.
 java.lang.String getInterfaceNameAnti(Plug antiPlug)
          Returns an interface name of the opposite Channel-side.
 java.lang.String getInterfaceNamePro(Plug proPlug)
          Returns an interface name of the same Channel-side.
 Plug[] getLeft()
          Returns the array of left-side objects (Plugs).
 int getLeftCount()
          Returns the left Channel-side count.
 java.lang.Object getLeftInterface()
          Returns the interface object of the left Channel-side.
 java.lang.String getLeftInterfaceName()
          Returns an interface name of the left Channel-side.
 Plug[] getPro(Plug proPlug)
          Returns the array of same-side objects (Plugs).
 Plug[] getRight()
          Returns the array of right-side objects (Plugs).
 int getRightCount()
          Returns the right Channel-side count.
 java.lang.Object getRightInterface()
          Returns the interface object of the right Channel-side.
 java.lang.String getRightInterfaceName()
          Returns an interface name of the right Channel-side.
 boolean isLeft(Plug oldPlug)
          Is the given Plug connected to the left Channel-side?
 boolean isRight(Plug oldPlug)
          Is the given Plug connected to the right Channel-side?
 boolean prepare()
          Prepares the Channel to regular operation.
 java.lang.Object setInterface(java.lang.Object newInterface, Plug called)
          Sets new interface object for the given Channel-side.
 void setInterfaceNames(java.lang.String _leftInterfaceName, java.lang.String _rightInterfaceName)
          (Re-)initialize both interface names.
 java.lang.Object setLeftInterface(java.lang.Object newLeftInterface)
          Sets new interface object for the left Channel-side.
 java.lang.Object setRightInterface(java.lang.Object newRightInterface)
          Sets new interface object for the right Channel-side.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

leftInterfaceName

protected java.lang.String leftInterfaceName
Fully-qualified interface name of the left side (called from the right side).


leftInterface

protected java.lang.Object leftInterface
Interface object for the left-side (called by right-side Piece[s]).


leftSet

protected java.util.HashSet<Plug> leftSet
Set of Plugs connected to the left side.


rightInterfaceName

protected java.lang.String rightInterfaceName
Fully-qualified interface name of the right side (called from the left side).


rightInterface

protected java.lang.Object rightInterface
Interface object for the right-side (called by left-side Piece[s]).


rightSet

protected java.util.HashSet<Plug> rightSet
Set of Plugs connected to the right side.

Constructor Detail

BasicChannel

public BasicChannel(java.lang.String _leftInterfaceName,
                    java.lang.String _rightInterfaceName)
Initializing constructor.

Parameters:
_leftInterfaceName - Fully-qualified interface name of the left side (called from the right side).
_rightInterfaceName - Fully-qualified interface name of the right side (called from the left side).
See Also:
setInterfaceNames(java.lang.String, java.lang.String)
Method Detail

setInterfaceNames

public void setInterfaceNames(java.lang.String _leftInterfaceName,
                              java.lang.String _rightInterfaceName)
(Re-)initialize both interface names.

Specified by:
setInterfaceNames in interface Channel
Parameters:
_leftInterfaceName - Fully-qualified interface name of the left side (called from the right side).
_rightInterfaceName - Fully-qualified interface name of the right side (called from the left side).
See Also:
getLeftInterfaceName(), getRightInterfaceName()

getLeftInterfaceName

public java.lang.String getLeftInterfaceName()
Returns an interface name of the left Channel-side.

Specified by:
getLeftInterfaceName in interface Channel
Returns:
Fully-qualified interface name of the left side (called from the right side).
See Also:
setInterfaceNames(java.lang.String, java.lang.String), getRightInterfaceName()

getRightInterfaceName

public java.lang.String getRightInterfaceName()
Returns an interface name of the right Channel-side.

Specified by:
getRightInterfaceName in interface Channel
Returns:
Fully-qualified interface name of the right side (called from the left side).
See Also:
setInterfaceNames(java.lang.String, java.lang.String), getLeftInterfaceName()

getInterfaceNamePro

public java.lang.String getInterfaceNamePro(Plug proPlug)
Returns an interface name of the same Channel-side.

Specified by:
getInterfaceNamePro in interface Channel
Parameters:
proPlug - The Plug connected to the same side.
Returns:
Fully-qualified interface name of the given Channel-side.
See Also:
getInterfaceNameAnti(cz.cuni.jagrlib.Plug)

getInterfaceNameAnti

public java.lang.String getInterfaceNameAnti(Plug antiPlug)
Returns an interface name of the opposite Channel-side.

Specified by:
getInterfaceNameAnti in interface Channel
Parameters:
antiPlug - The Plug connected to the opposite side.
Returns:
Fully-qualified interface name of the given Channel-side.
See Also:
getInterfaceNamePro(cz.cuni.jagrlib.Plug)

setLeftInterface

public java.lang.Object setLeftInterface(java.lang.Object newLeftInterface)
Sets new interface object for the left Channel-side.

Specified by:
setLeftInterface in interface Channel
Parameters:
newLeftInterface - New interface object (= object called from the opposite side).
Returns:
The old interface object or null.
See Also:
setRightInterface(java.lang.Object), setInterface(java.lang.Object, cz.cuni.jagrlib.Plug)

setRightInterface

public java.lang.Object setRightInterface(java.lang.Object newRightInterface)
Sets new interface object for the right Channel-side.

Specified by:
setRightInterface in interface Channel
Parameters:
newRightInterface - New interface object (= object called from the opposite side).
Returns:
The old interface object or null.
See Also:
setLeftInterface(java.lang.Object), setInterface(java.lang.Object, cz.cuni.jagrlib.Plug)

setInterface

public java.lang.Object setInterface(java.lang.Object newInterface,
                                     Plug called)
Sets new interface object for the given Channel-side. The side is defined by the Plug connected to it.

Specified by:
setInterface in interface Channel
Parameters:
newInterface - New interface object (= object called from the opposite side).
called - The Plug defining the side.
Returns:
The old interface object or null.
See Also:
setLeftInterface(java.lang.Object), setRightInterface(java.lang.Object)

getLeftInterface

public java.lang.Object getLeftInterface()
Returns the interface object of the left Channel-side.

Specified by:
getLeftInterface in interface Channel
Returns:
The interface object or null.
See Also:
setLeftInterface(java.lang.Object)

getRightInterface

public java.lang.Object getRightInterface()
Returns the interface object of the right Channel-side.

Specified by:
getRightInterface in interface Channel
Returns:
The interface object or null.
See Also:
setRightInterface(java.lang.Object)

getInterface

public java.lang.Object getInterface(Plug caller)
Returns the interface object of the given Channel-side. The side is defined by the Plug which calls it.

Specified by:
getInterface in interface Channel
Parameters:
caller - The Plug defining the opposite (caller) side.
Returns:
The interface object or null.
See Also:
setInterface(java.lang.Object, cz.cuni.jagrlib.Plug)

connectLeft

public void connectLeft(Plug newPlug)
Connects a new Plug to the left Channel-side. Updates the Plug's Piece, too.

Specified by:
connectLeft in interface Channel
Parameters:
newPlug - The Plug to be connected.
See Also:
connectRight(cz.cuni.jagrlib.Plug)

connectRight

public void connectRight(Plug newPlug)
Connects a new Plug to the right Channel-side.

Specified by:
connectRight in interface Channel
Parameters:
newPlug - The Plug to be connected.
See Also:
connectLeft(cz.cuni.jagrlib.Plug)

connectPro

public void connectPro(Plug newPlug,
                       Plug proPlug)
Connects a new Plug to the same Channel-side.

Specified by:
connectPro in interface Channel
Parameters:
newPlug - The Plug to be connected.
proPlug - The Plug connected to the same side.
See Also:
connectAnti(cz.cuni.jagrlib.Plug, cz.cuni.jagrlib.Plug)

connectAnti

public void connectAnti(Plug newPlug,
                        Plug antiPlug)
Connects a new Plug to the opposite Channel-side.

Specified by:
connectAnti in interface Channel
Parameters:
newPlug - The Plug to be connected.
antiPlug - The Plug connected to the opposite side.
See Also:
connectPro(cz.cuni.jagrlib.Plug, cz.cuni.jagrlib.Plug)

disconnect

public void disconnect(Plug oldPlug)
Disconnects the old Plug from the Channel.

Specified by:
disconnect in interface Channel
Parameters:
oldPlug - The Plug to be disconnected.
See Also:
disconnectAll()

disconnectAll

public void disconnectAll()
Disconnects all Plugs from the Channel.

Specified by:
disconnectAll in interface Channel
See Also:
disconnect(cz.cuni.jagrlib.Plug)

getLeftCount

public int getLeftCount()
Returns the left Channel-side count.

Specified by:
getLeftCount in interface Channel
Returns:
The left-side count (number of Plugs connected to that side).
See Also:
getRightCount()

getRightCount

public int getRightCount()
Returns the right Channel-side count.

Specified by:
getRightCount in interface Channel
Returns:
The right-side count (number of Plugs connected to that side).
See Also:
getLeftCount()

isLeft

public boolean isLeft(Plug oldPlug)
Is the given Plug connected to the left Channel-side?

Specified by:
isLeft in interface Channel
Parameters:
oldPlug - The checked Plug.
Returns:
true if the given Plug is connected to the left side.
See Also:
isRight(cz.cuni.jagrlib.Plug)

isRight

public boolean isRight(Plug oldPlug)
Is the given Plug connected to the right Channel-side?

Specified by:
isRight in interface Channel
Parameters:
oldPlug - The checked Plug.
Returns:
true if the given Plug is connected to the right side.
See Also:
isLeft(cz.cuni.jagrlib.Plug)

getLeft

public Plug[] getLeft()
Returns the array of left-side objects (Plugs).

Specified by:
getLeft in interface Channel
Returns:
The array of Plugs connected to the left side.

getRight

public Plug[] getRight()
Returns the array of right-side objects (Plugs).

Specified by:
getRight in interface Channel
Returns:
The array of Plugs connected to the right side.

getPro

public Plug[] getPro(Plug proPlug)
Returns the array of same-side objects (Plugs).

Specified by:
getPro in interface Channel
Parameters:
proPlug - The Plug connected to the same side.
Returns:
The array of Plugs.

getAnti

public Plug[] getAnti(Plug antiPlug)
Returns the array of opposite-side objects (Plugs).

Specified by:
getAnti in interface Channel
Parameters:
antiPlug - The Plug connected to the opposite side.
Returns:
The array of Plugs.

prepare

public boolean prepare()
Prepares the Channel to regular operation.

Specified by:
prepare in interface Channel
Returns:
true if everything is OK (Channel is prepared for operation).