1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package zeus.actors.outtrays;
23
24
25 import javax.naming.*;
26 import java.util.*;
27 import zeus.util.*;
28
29
30
31 import javax.rmi.*;
32 import zeus.concepts.*;
33 import zeus.actors.*;
34 import java.io.*;
35 import fipa97.FIPA_Agent_97;
36 import fipa97.FIPA_Agent_97Helper;
37 import org.omg.CORBA.*;
38 import org.omg.CORBA.portable.*;
39 import org.omg.CosNaming.*;
40 import zeus.actors.factories.*;
41 import javax.agent.service.*;
42 import javax.agent.*;
43
44 /***
45 This class is a FIPA complient PostMan that can be used to build an
46 ACC agent which when working with the NameServer provides a link between
47 the Zeus platform and other FIPA complient platforms
48 */
49 public class FIPA_PostMan extends zeus.actors.PostMan {
50
51 protected javax.naming.Context initialNamingContext = null;
52 private FileWriter log;
53 private File file = null;
54 public FIPA_PostMan(MailBox mbox, Queue outMail, Queue ccMail, Address myAddress) {
55
56
57 this.mbox = mbox;
58 this.outMail = outMail;
59 this.ccMail = ccMail;
60 this.myAddress = myAddress;
61
62 if ( ccMail == null )
63 this.setPriority(Thread.NORM_PRIORITY);
64
65 try {
66 initialNamingContext = new InitialContext();}
67 catch (Exception e) {
68 e.printStackTrace(); }
69 this.setName ("FIPA_PostMan");
70 this.start();
71
72 }
73
74
75 public void run() {
76 FIPAPerformative msg;
77 String receiver;
78 boolean done = false;
79 dispatching = true;
80
81 try {
82 file = new File (SystemProps.getProperty("http_root")+ SystemProps.getProperty("out_log"));
83 log = new FileWriter (file,true);
84
85 }
86 catch (Exception e) {
87 e.printStackTrace();
88 }
89 while( dispatching ) {
90 try {
91 msg = (FIPAPerformative) outMail.dequeue();
92
93
94
95
96
97 done = false;
98 Enumeration recs = msg.getFIPAReceivers();
99 while (recs.hasMoreElements () && !done) {
100 try {
101 FIPA_AID_Address addr = (FIPA_AID_Address) recs.nextElement();
102 System.out.println(msg.toString());
103 done = postFIPAMsg (msg, addr);
104 file.setLastModified(java.lang.System.currentTimeMillis());
105 }
106 catch (Exception e) {
107 System.out.println("exception in address, probably proprietary/ unhandled transport");
108 System.out.println("zeus is trying next address");
109 e.printStackTrace(); }
110 catch (Error er) {
111 System.out.println("error in address, probably proprietary/ unhandled transport");
112 System.out.println("zeus is trying next address");
113 er.printStackTrace();
114 }
115 System.out.println("recs = " + recs.toString());
116 if (done) System.out.println("done = true");
117 else System.out.println("done = false");
118 }
119 System.out.println("iterating");
120 } catch (Exception e) {
121 e.printStackTrace(); }
122 catch (Error er) {
123 er.printStackTrace();
124 }
125
126
127
128 }
129 }
130
131
132 /***
133 posts the message to the appropriate transport, will set the return address to
134 */
135 public boolean postFIPAMsg( FIPAPerformative msg, FIPA_AID_Address addr ) {
136 try {
137 boolean isOk = false;
138 int nTry = 0;
139
140
141
142 Iterator addressIter = addr.iterator();
143 String thisAddress = new String();
144 while( addressIter.hasNext()) {
145
146 thisAddress = (String) addressIter.next();
147 debug ("trying : " + thisAddress);
148 TransportFactoryMethod tfm = new TransportFactoryMethod();
149 TransportFactory tFactory = tfm.getTransportFactory();
150 tFactory.setLog(file);
151 try {
152 OutTray trans = tFactory.getTransport(thisAddress);
153 javax.agent.Envelope env = msg.jasEnvelope(addr,thisAddress);
154 trans.send (env);
155 return (true);
156 }
157 catch (TransportUnsupportedException tue) {
158 tue.printStackTrace();
159 }
160 catch (UnsuitableMessageException ume) {
161 ume.printStackTrace();
162 }
163 catch (Exception e) {
164 e.printStackTrace();
165
166 }
167 catch (Error er) {
168
169 }
170 }
171 return false; }
172 catch (Exception e){
173 e.printStackTrace();
174 return false;
175 }
176 }
177
178 private void debug(String str) {
179
180 }
181
182
183
184
185
186 }