View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
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      //protected Context initialNamingContext = null; 
57   // private String  connectionPoint   = new String ("iiop://127.0.0.1:900"); 
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 }