1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package zeus.actors.intrays;
27
28 import java.net.*;
29 import java.io.*;
30 import java.util.*;
31 import zeus.util.*;
32 import zeus.concepts.*;
33 import zeus.actors.*;
34 import zeus.agents.*;
35 import javax.naming.*;
36 import java.net.*;
37 import java.io.*;
38 import java.util.*;
39 import zeus.util.*;
40 import zeus.concepts.*;
41
42 import javax.rmi.*;
43 import java.rmi.*;
44 import fipa97.FIPA_Agent_97;
45 /***
46 This is an extention of the Server class which is normally used in Zeus
47 Instead of providing a sockets/TCPIP based transport this class provides a
48 IIOP based transport as per the FIPA specs<p>
49 Perhaps it should be called IIOP_Server?
50 This is not well implemented yet, and Zeus_ACC_Server is the one to use instead.
51
52 */
53
54 public class FIPA_Server extends Server implements InTray {
55
56
57
58 protected AgentContext context = null;
59 private Queue msgQ = new Queue("fipaIn");
60 private ZeusParser parser = new ZeusParser();
61
62
63 public FIPA_Server() {
64 super();
65
66 }
67
68 public FIPA_Server(String hostAddress, String name) {
69 Hashtable env = new Hashtable();
70 env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
71 env.put(Context.PROVIDER_URL,hostAddress);
72 try {
73 org.omg.CORBA.ORB myORB = org.omg.CORBA.ORB.init(new String[0], null);
74 FIPA_Agent_97 fipa = new FIPA_message();
75 Thread corba_messageThread = new Thread((FIPA_message)fipa);
76 corba_messageThread.setPriority(Thread.MIN_PRIORITY);
77 corba_messageThread.start();
78 ((FIPA_message)fipa).register(msgQ);
79 Context initialNamingContext = new InitialContext(env);
80 initialNamingContext.rebind(name,fipa);
81 }
82 catch (Exception e) {
83 e.printStackTrace();
84 }
85 this.start();
86 this.setName("FIPA_Server");
87 }
88
89
90 /***
91 This method should call an agnostic message handler....
92 Right now, it just prints the message to System.out
93
94 */
95 public void run() {
96 processing = true;
97
98 while (processing) {
99 String text = this.pop();
100 try {
101 System.out.println(text);
102 }
103 catch (Exception e) {
104 e.printStackTrace();
105 }
106
107 yield();
108 }
109 }
110
111
112 public String pop () {
113 return (String) msgQ.dequeue();
114 }
115
116 }