de.sciss.jcollider
Class OSCResponderNode

java.lang.Object
  extended by de.sciss.jcollider.OSCResponderNode
All Implemented Interfaces:
de.sciss.net.OSCListener

public class OSCResponderNode
extends java.lang.Object
implements de.sciss.net.OSCListener

Similar operation as the SClang class of the same name, but slightly different implementation, based on the new OSCMultiResponder class and NetUtil.

As of v0.29 the creator signature had to be changed to use a Server instead of a network address, unfortunately (a side effect of using OSCClient in Server and OSCMultiResponder). So you may need to update old code.

Version:
0.36, 08-Oct-09
Author:
Hanns Holger Rutz

Nested Class Summary
static interface OSCResponderNode.Action
           
 
Constructor Summary
OSCResponderNode(Server s, java.lang.String cmdName, de.sciss.net.OSCListener action)
          Creates a new responder node to listen for messages coming in from the given server.
OSCResponderNode(Server s, java.lang.String cmdName, OSCResponderNode.Action action)
          Creates a new responder node to listen for messages coming in from the given server.
 
Method Summary
 OSCResponderNode add()
          Adds the node to the list of actively listening nodes.
 java.lang.String getCommandName()
          Queries the name which is used as the message filter
 boolean isListening()
          Queries the node's state.
 void messageReceived(de.sciss.net.OSCMessage msg, java.net.SocketAddress sender, long time)
          This method is called as part of the implementation of the OSCListener interface.
 OSCResponderNode remove()
          Removes the node from the list of actively listening nodes.
 OSCResponderNode removeWhenDone()
          Tags the node to remove itself after the next unfiltered message arrived.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OSCResponderNode

public OSCResponderNode(Server s,
                        java.lang.String cmdName,
                        de.sciss.net.OSCListener action)
Creates a new responder node to listen for messages coming in from the given server. Filters out messages different from the specified command name. Upon reception, the provided OSCListener is invoked.

After creating the responder, the add method has to be called separately to actually start the listening process.

Parameters:
s - server of incoming messages
cmdName - name of the OSC command at whose arrival the action is invoked
action - the action's messageReceived method is called upon message reception. Note that just as specified in the OSCListener interface, the action should not assume to be in any particular thread. The current implementation calls the action in the OSC listening thread, but this is not guaranteed. Calls to Swing components should be deferred appropriately.
See Also:
Server, add()

OSCResponderNode

public OSCResponderNode(Server s,
                        java.lang.String cmdName,
                        OSCResponderNode.Action action)
Creates a new responder node to listen for messages coming in from the given server. Filters out messages different from the specified command name. Upon reception, the provided action is invoked.

After creating the responder, the add method has to be called separately to actually start the listening process.

Parameters:
s - server of incoming messages
cmdName - name of the OSC command at whose arrival the action is invoked
action - the action's respond method is called upon message reception. Note that just as specified in the OSCListener interface, the action should not assume to be in any particular thread. The current implementation calls the action in the OSC listening thread, but this is not guaranteed. Calls to Swing components should be deferred appropriately.
See Also:
Server, add()
Method Detail

getCommandName

public java.lang.String getCommandName()
Queries the name which is used as the message filter

Returns:
the name of the OSC command to which this responder listens

add

public OSCResponderNode add()
                     throws java.io.IOException
Adds the node to the list of actively listening nodes. If you are uncertain about the node's state, check isListening first, since this method will throw an IllegalStateException if you try to add it twice.

Returns:
the responder node (for convenience)
Throws:
java.lang.IllegalStateException - if the node has already been added
java.io.IOException
See Also:
remove(), isListening()

isListening

public boolean isListening()
Queries the node's state.

Returns:
true if the node is active (was added), false otherwise (newly created node or removed)

removeWhenDone

public OSCResponderNode removeWhenDone()
Tags the node to remove itself after the next unfiltered message arrived. If the node shall receive exactly one message, a clean code must call this method before calling the add method.

Returns:
the responder node (for convenience)

messageReceived

public void messageReceived(de.sciss.net.OSCMessage msg,
                            java.net.SocketAddress sender,
                            long time)
This method is called as part of the implementation of the OSCListener interface. It dispatches the message to the action. If removeWhenDone was called, it will remove the node after the action returns.

Specified by:
messageReceived in interface de.sciss.net.OSCListener
See Also:
removeWhenDone()

remove

public OSCResponderNode remove()
Removes the node from the list of actively listening nodes. If the node was already removed, this method does nothing.

Returns:
the responder node (for convenience)
Throws:
java.io.IOException - if there was a problem
See Also:
add()