org.robokind.impl.messaging
Class JMSAvroServiceFacade<Config extends org.apache.avro.generic.IndexedRecord>

java.lang.Object
  extended by org.robokind.api.common.playable.AbstractPlayable
      extended by org.robokind.impl.messaging.JMSAvroServiceFacade<Config>
Type Parameters:
Config - type of Avro Record used to configure the service
All Implemented Interfaces:
Playable, RemoteService<Config>

public class JMSAvroServiceFacade<Config extends org.apache.avro.generic.IndexedRecord>
extends AbstractPlayable
implements RemoteService<Config>

A facade for controlling a RemoteService using Avro and JMS (Qpid). A JMSAvroServiceFacade has a JMS MessageProducer for sending commands to the RemoteService, and a JMS MessageConsumer for receiving error messages. * (Error messages are not yet completed)

Author:
Matthew Stevenson

Field Summary
static String COMMAND_MIME_TYPE
          Custom content/mime type used in the JMS header for service command
static String CONFIG_MIME_TYPE
          Custom content/mime type used in the JMS header for config Records
 
Fields inherited from class org.robokind.api.common.playable.AbstractPlayable
myElapsedPauseTime, myPauseTime, myPlayableListeners, myPlayState, myResumeTime, myStartTime, myStopTime
 
Constructor Summary
JMSAvroServiceFacade(Class<Config> configClass, Config reusableConfig, javax.jms.Session session, javax.jms.Destination commandDest, javax.jms.Destination errorDest)
          Creates a new JMSAvroServiceFacade.
JMSAvroServiceFacade(Class<Config> configClass, Config reusableConfig, javax.jms.Session session, javax.jms.MessageProducer commandSender, javax.jms.MessageConsumer errorReceiver)
          Creates a new JMSAvroServiceFacade.
 
Method Summary
 Class<Config> getConfigClass()
           
 Config getReusableConfig()
           
 void initialize(Config config)
           
 boolean onComplete(long time)
           
 boolean onPause(long time)
           
 boolean onResume(long time)
           
 boolean onStart(long time)
           
 boolean onStop(long time)
           
protected
<T extends org.apache.avro.generic.IndexedRecord>
void
send(T t, String contentType)
          Sends a custom Avro Record to the service.
protected  boolean sendCommand(ServiceCommandType command)
          Sends a service command.
 void setReceiver(javax.jms.MessageConsumer consumer)
          Sets the MessageConsumer to receive errors.
 void setSender(javax.jms.MessageProducer producer)
          Sets the MessagePropducer to send commands.
 void setSession(javax.jms.Session session)
          Sets the JMS Session for creating BytesMessages.
 
Methods inherited from class org.robokind.api.common.playable.AbstractPlayable
addPlayableListener, afterComplete, complete, firePlayStateChanged, getElapsedPauseTime, getElapsedPlayTime, getPauseTime, getPlayState, getResumeTime, getStartTime, getStopTime, pause, removePlayableListener, resume, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.robokind.api.common.playable.Playable
addPlayableListener, complete, getElapsedPauseTime, getElapsedPlayTime, getPauseTime, getPlayState, getResumeTime, getStartTime, getStopTime, pause, removePlayableListener, resume, start, stop
 

Field Detail

CONFIG_MIME_TYPE

public static final String CONFIG_MIME_TYPE
Custom content/mime type used in the JMS header for config Records

See Also:
Constant Field Values

COMMAND_MIME_TYPE

public static final String COMMAND_MIME_TYPE
Custom content/mime type used in the JMS header for service command

See Also:
Constant Field Values
Constructor Detail

JMSAvroServiceFacade

public JMSAvroServiceFacade(Class<Config> configClass,
                            Config reusableConfig,
                            javax.jms.Session session,
                            javax.jms.Destination commandDest,
                            javax.jms.Destination errorDest)
                     throws javax.jms.JMSException
Creates a new JMSAvroServiceFacade.

Parameters:
configClass - class of the config record
reusableConfig - reusable instance of the config
session - JMS session for sending Records
commandDest - JMS destination for commands
errorDest - JMS destination for errors
Throws:
javax.jms.JMSException - if there is an error creating producers and consumers

JMSAvroServiceFacade

public JMSAvroServiceFacade(Class<Config> configClass,
                            Config reusableConfig,
                            javax.jms.Session session,
                            javax.jms.MessageProducer commandSender,
                            javax.jms.MessageConsumer errorReceiver)
Creates a new JMSAvroServiceFacade.

Parameters:
configClass - class of the config record
reusableConfig - reusable instance of the config
session - JMS session for sending Records
commandSender - MessagePropducer to send commands
errorReceiver - MessageConsumer to receive errors
Method Detail

setSession

public void setSession(javax.jms.Session session)
Sets the JMS Session for creating BytesMessages.

Parameters:
session - JMS Session to use

setSender

public void setSender(javax.jms.MessageProducer producer)
Sets the MessagePropducer to send commands.

Parameters:
producer - MessageProducer to use

setReceiver

public void setReceiver(javax.jms.MessageConsumer consumer)
Sets the MessageConsumer to receive errors.

Parameters:
consumer - MessageConsumer to set

initialize

public void initialize(Config config)
                throws IOException,
                       javax.jms.JMSException,
                       Exception
Specified by:
initialize in interface RemoteService<Config extends org.apache.avro.generic.IndexedRecord>
Throws:
IOException
javax.jms.JMSException
Exception

onStart

public boolean onStart(long time)
Specified by:
onStart in class AbstractPlayable

onPause

public boolean onPause(long time)
Specified by:
onPause in class AbstractPlayable

onResume

public boolean onResume(long time)
Specified by:
onResume in class AbstractPlayable

onComplete

public boolean onComplete(long time)
Specified by:
onComplete in class AbstractPlayable

onStop

public boolean onStop(long time)
Specified by:
onStop in class AbstractPlayable

send

protected <T extends org.apache.avro.generic.IndexedRecord> void send(T t,
                                                                      String contentType)
             throws IOException,
                    javax.jms.JMSException
Sends a custom Avro Record to the service.

Type Parameters:
T - type of Avro Record to send
Parameters:
t - the Record to send
contentType - optional content type for the JMS header
Throws:
IOException - on errors packing the Record into a JMS BytesMessage
javax.jms.JMSException - on errors sending the Record

sendCommand

protected boolean sendCommand(ServiceCommandType command)
Sends a service command.

Parameters:
command - command to send
Returns:
true if successful

getConfigClass

public Class<Config> getConfigClass()
Specified by:
getConfigClass in interface RemoteService<Config extends org.apache.avro.generic.IndexedRecord>

getReusableConfig

public Config getReusableConfig()
Specified by:
getReusableConfig in interface RemoteService<Config extends org.apache.avro.generic.IndexedRecord>


Copyright © 2011-2012. All Rights Reserved.