1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package zeus.actors.outtrays;
22
23 import javax.agent.service.*;
24 import javax.agent.*;
25 import zeus.actors.*;
26 import FIPA.*;
27
28 /***
29 Class that provides a MTS that implements the FIPA 2000 spec (XC00075)
30 @author Simon Thompson
31 @since 1.1
32 */
33 public class FIPA_2000_IIOP_Transport implements OutTray {
34
35 /***
36 mts used to internally implement transport functionality
37 */
38 private FIPA.MTS mts = null;
39
40
41
42 /***
43 this transport must be implemented with a valid FIPA.MTS object. <p>
44 The FIPA.MTS in question should have been generated by calling a
45 CORBA orb and retreiving a reference to a FIPA.MTS that had been
46 bound there by a third party. <p>
47 The recommeneded way of doing this is to use zeus.actors.service.TransportMethod to
48 generate a TransportFactory (probably the IIOP_Z_TransportFactory, but
49 possibly another one depending on what version of zeus or other related
50 product you are using). Once you have the TransportFactory reference you must
51 then call getTransport which will return an instance of this class.
52 <p> Alternatively, you must venture into the realms of corba coding and
53 sort this out yourself!
54 <p>
55 @see zeus.actors.service.TransportMethod*/
56 public FIPA_2000_IIOP_Transport (FIPA.MTS mts) {
57 this.mts = mts;
58 }
59
60
61 public void send (Object obj) throws UnsuitableMessageException {
62 try {
63 javax.agent.Envelope env = (javax.agent.Envelope) obj;
64 send (env);
65 } catch (ClassCastException cce) {
66 throw new UnsuitableMessageException ("Must be javax.agent.envelope to work with this transport");
67 }catch (Exception e) {
68 e.printStackTrace();
69 throw new UnsuitableMessageException ("Bad message in send() - unknown problem, Excepiton printed to sout");
70
71 }
72 }
73
74
75 public void send (javax.agent.Envelope envelope) {
76 Identifier sender = envelope.getSender();
77 Identifier receiver = envelope.getReceiver();
78 Object payload = envelope.getObject();
79 try {
80 zeus.concepts.FIPAPerformative fperf = (zeus.concepts.FIPAPerformative) payload;
81 debug ("Performative is : \n" + fperf.toFIPAString());
82 FIPA.Envelope fenv = new FIPA.Envelope();
83
84 try {
85 fenv.to = fperf.getReceiversAgentID();
86
87 } catch (NullPointerException npe) { ;}
88 try {
89 fenv.from = fperf.getSenderAgentID();
90 } catch (NullPointerException npe) {
91 fenv.from = new FIPA.AgentID[0];}
92
93 try {
94 fenv.comments = new String ("Zeus Agent Building Environment v1.1");
95 } catch (NullPointerException npe) { ;}
96
97 fenv.payloadLength = -1;
98
99 fenv.payloadEncoding = new String ("String");
100
101 fenv.aclRepresentation = new String ("fipa.acl.rep.string.std");
102
103 fenv.date = new FIPA.DateTime[0];
104
105 fenv.encrypted = new String [1];
106
107 fenv.encrypted[0] = fperf.getEncryptionScheme();
108
109 fenv.intendedReceiver = fperf.getReceiversAgentID ();
110
111
112
113 fenv.received = new FIPA.ReceivedObject[0];
114
115 fenv.transportBehaviour = new FIPA.Property[0][0];
116
117 fenv.userDefinedProperties = new FIPA.Property[0];
118
119 FIPA.Envelope envelopes[] = {fenv};
120
121 FIPA.FipaMessage message = new FIPA.FipaMessage(envelopes,fperf.toFIPAString().getBytes());
122 debug ("Sending message "+message.toString());
123 mts.message (message);
124 debug ("message sent");
125
126
127 }
128 catch (ClassCastException cce) {
129
130
131 cce.printStackTrace();
132 return;
133 }
134 }
135
136
137
138 private void debug (String str) {
139 System.out.println("FIPA_2000_IIOP_Transport >>" + str);
140 }
141
142 }