jadex.platform.service.message.MessageAgent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-platform Show documentation
Show all versions of jadex-platform Show documentation
The Jadex platform package contains implementations of platform services as well as the platform component itself.
package jadex.platform.service.message;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import jadex.base.IRootComponentConfiguration;
import jadex.bridge.IInternalAccess;
import jadex.bridge.nonfunctional.annotation.NameValue;
import jadex.bridge.service.types.message.IMessageService;
import jadex.commons.SReflect;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.Argument;
import jadex.micro.annotation.Arguments;
import jadex.micro.annotation.Implementation;
import jadex.micro.annotation.Properties;
import jadex.micro.annotation.ProvidedService;
import jadex.micro.annotation.ProvidedServices;
import jadex.platform.service.message.transport.ITransport;
/**
* Agent that provides the message service.
*/
@Agent
@Arguments({
@Argument(name="localtransport", clazz=boolean.class, defaultvalue="true"),
@Argument(name="tcptransport", clazz=boolean.class, defaultvalue="false"),
@Argument(name="niotcptransport", clazz=boolean.class, defaultvalue="true"),
@Argument(name="ssltcptransport", clazz=boolean.class, defaultvalue="false"),
@Argument(name="relaytransport", clazz=boolean.class, defaultvalue="false"),
@Argument(name="tcpport", clazz=int.class),
@Argument(name="niotcpport", clazz=int.class),
@Argument(name="ssltcpport", clazz=int.class),
@Argument(name="relayaddress", clazz=String.class),
@Argument(name="relaysecurity", clazz=boolean.class, defaultvalue="false"),
@Argument(name="relayawaonly", clazz=boolean.class, defaultvalue="false"),
@Argument(name="binarymessages", clazz=boolean.class, defaultvalue="true"),
@Argument(name="strictcom", clazz=boolean.class, defaultvalue="false"),
})
//@ProvidedServices(@ProvidedService(type=IMessageService.class, implementation=@Implementation(expression="new jadex.platform.service.message.MessageService($component, $component.getLogger(), new jadex.platform.service.message.transport.ITransport[]{$args.localtransport? new jadex.platform.service.message.transport.localmtp.LocalTransport($component): null, $args.tcptransport? new jadex.platform.service.message.transport.tcpmtp.TCPTransport($component, $args.tcpport): null, MessageAgent.createTransport(\"niotcpmtp.NIOTCPTransport\", new Object[] {$args.niotcptransport, $component, $args.niotcpport, $component.getLogger()}), $args.ssltcptransport? jadex.platform.service.message.transport.ssltcpmtp.SSLTCPTransport.create($component, $args.ssltcpport): null, $args.relaytransport? new jadex.platform.service.message.transport.httprelaymtp.HttpRelayTransport($component, $args.relayaddress, $args.relaysecurity): null, MessageAgent.createTransport(\"udpmtp.UdpTransport\", $component)}, new jadex.bridge.service.types.message.MessageType[]{new jadex.bridge.fipa.FIPAMessageType()}, null, $args.binarymessages? jadex.bridge.fipa.SFipa.JADEX_BINARY: jadex.bridge.fipa.SFipa.JADEX_XML, $args.binarymessages? new jadex.platform.service.message.transport.codecs.CodecFactory(null, new Class[]{jadex.platform.service.message.transport.codecs.JadexBinaryCodec.class, jadex.platform.service.message.transport.codecs.GZIPCodec.class} ): new jadex.platform.service.message.transport.codecs.CodecFactory(), $args.strictcom)", proxytype=Implementation.PROXYTYPE_RAW)))
@ProvidedServices(@ProvidedService(type=IMessageService.class, implementation=@Implementation(expression="new jadex.platform.service.message.MessageService($component, $component.getLogger(), MessageAgent.createTransports($component, $args), new jadex.bridge.service.types.message.MessageType[]{new jadex.bridge.fipa.FIPAMessageType()}, null, $args.binarymessages? jadex.bridge.fipa.SFipa.JADEX_BINARY: jadex.bridge.fipa.SFipa.JADEX_XML, $args.binarymessages? new jadex.platform.service.message.transport.codecs.CodecFactory(null, new Class[]{jadex.platform.service.message.transport.codecs.JadexBinaryCodec.class, jadex.platform.service.message.transport.codecs.GZIPCodec.class} ): new jadex.platform.service.message.transport.codecs.CodecFactory(), $args.strictcom)", proxytype=Implementation.PROXYTYPE_RAW)))
@Properties(value=@NameValue(name="system", value="true"))
public class MessageAgent
{
/** Transport configuration
* Format:
*/
public static final String[] TPCONF = new String[]
{// Class EnableArg Constructor Args
"jadex.platform.service.message.transport.localmtp.LocalTransport", "localtransport", "component",
"jadex.platform.service.message.transport.tcpmtp.TCPTransport", "tcptransport", "component,tcpport",
"jadex.platform.service.message.transport.niotcpmtp.NIOTCPTransport", "niotcptransport", "component," + IRootComponentConfiguration.NIOTCPPORT +",componentlogger",
"jadex.platform.service.message.transport.ssltcpmtp.SSLTCPTransport", "ssltcptransport", "component,"+IRootComponentConfiguration.SSLTCPPORT,
"com.actoron.platform.service.message.transport.udpmtp.UdpTransport", "null", "component,false,true",
"jadex.platform.service.message.transport.httprelaymtp.HttpRelayTransport", "relaytransport", "component,relayaddress,relaysecurity,relayawaonly"
};
/**
* Initializes the transports.
*
* @param ia Component.
* @param args The component arguments.
* @return Set of transports.
*/
public static ITransport[] createTransports(IInternalAccess ia, LinkedHashMap args)
{
if (TPCONF.length % 3 != 0)
{
throw new IllegalArgumentException("Transport configuration broken.");
}
ITransport[] transports = new ITransport[TPCONF.length / 3];
for (int i = 0; i < TPCONF.length; i = i + 3)
{
String clazz = TPCONF[i];
if (!Boolean.FALSE.equals(args.get(TPCONF[i + 1])))
{
List