View Javadoc

1   /*
2   research product only
3   */
4   
5   package zeus.actors.intrays;
6   
7   import java.net.*;
8   import java.io.*;
9   import java.util.*;
10  import zeus.util.*;
11  import zeus.concepts.*;
12  import zeus.actors.*;
13  import zeus.agents.*;
14  import javax.naming.*;
15  import java.net.*;
16  import java.io.*;
17  import java.util.*;
18  import zeus.util.*;
19  import zeus.concepts.*;
20  import org.omg.CosNaming.*;
21  import org.omg.CORBA.*;
22  
23  
24  import javax.rmi.*;
25  import java.rmi.*; 
26  import FIPA.*;
27  /***
28  This class allows us to communicate agent to agent in a container
29  via method calls - not very agent, but high performance; so may be 
30  of use in some applications.        
31  */
32  
33  public class Container_Server extends Server implements InTray {
34          
35  protected AgentContext context = null; 
36  private Queue  msgQ = new Queue("ContQueue");    
37  private ZeusParser parser = new ZeusParser();
38  private FIPA_2000_Handler handler = null; 
39  String fsep = System.getProperty("file.separator");
40  private String containerName = SystemProps.getProperty("container.name");  
41  private String name = null;      
42  
43  
44  public Container_Server(FIPA_2000_Handler handler, String host, String port , String name, String threadId) {
45  	Container_Connection conn = new Container_Connection(msgQ); 
46          Thread containerThread = new Thread(conn);
47          this.name = name;
48  	containerThread.start(); 
49  	this.handler = handler;
50  	Thread thr = new Thread (this);
51  	thr.start(); 
52  }
53        
54        
55  /***
56      This method should call an agnostic message handler....
57  
58      */
59  public void run() {
60      processing = true;
61      while (processing) {     
62          FIPA.FipaMessage message = this.pop();
63  	            try { 
64  	                handler.handle(message); 
65  	            }
66  	            catch (Exception e) { 
67  	                e.printStackTrace(); 
68  	                }
69      	
70  	yield(); 
71  	}	    
72      }    
73          
74             
75  public FIPA.FipaMessage pop () { 
76      return (FIPA.FipaMessage) msgQ.dequeue(); 
77  }
78  
79  
80  
81   /*** 
82  	makes an adderss of container@containerId/agentName
83      */
84      public String getResponseAddress() { 
85          return new String ("container@" + containerName+"/" + name); 
86      }
87   
88       
89  }