📄 zeus_acc_server.java
字号:
fw.close();} catch (Exception ne) { ne.printStackTrace(); }
}
}
/**
* set up a forwarding rule, if one is not already present.
*/
private void setHandleMessage(FIPA_AID_Address faddress, String alias) {
if (!faddress.getForwardingRuleSet()) {
MsgHandler handler = context.getMsgHandler();
String msg_pattern[] = {"receiver",alias};
handler.addRule(new MessageRuleImpl(context.newId("Rule"),msg_pattern, this, "forward"));
faddress.setForwardingRuleSet(true);
}
}
/**
* provides a basic mechanism for getting aliases for agents on other platforms
* into the Zeus address space. If this method is called from the ACC agent
* stub it can be used to setup zeus names and fipa forwarding in the ANServer and
* in the ACC
*/
public void setFIPAAlias(String name, String address) {
FIPA_AddressBook addresses = ((FIPA_AddressBook)context.getAddressBook());
FIPAPerformative fmsg = parser.fipaPerformative(address);
FIPA_AID_Address fAddress = fmsg.getSender_As_FIPA_AID();
fAddress = addresses.checkAddress(fAddress);
if (fAddress.getAlias() == null){
fAddress.setAlias(name);
registerAlias(fAddress,name);
setHandleMessage(fAddress,name);
addresses.add(fAddress);
}
}
/**
* provides a basic mechanism for getting aliases for agents on other platforms
* into the Zeus address space. If this method is called from the ACC agent
* stub it can be used to setup zeus names and fipa forwarding in the ANServer and
* in the ACC
*/
public void setFIPAAlias(String name, FIPA_AID_Address fAddress) {
FIPA_AddressBook addresses = ((FIPA_AddressBook)context.getAddressBook());
fAddress = addresses.checkAddress(fAddress);
if (fAddress.getAlias() == null) {
fAddress.setAlias(name);
registerAlias(fAddress,name);
setHandleMessage(fAddress,name);
addresses.add(fAddress);
}
}
/**
* forward is the method called when the MsgHandler fires a MessageRule that is setup
* by the setHandleMessage method.
* It converts the Zeus Performative into a FIPA performative, does any address mapping
* that is needed and sends the message to the FIPA_postman.
*/
public void forward(Performative perf) {
if (perf.getSender().startsWith("Nameserver")) return;
if (perf.getSender().startsWith("Facilitator")) return; // god knows
try {
FIPAPerformative fPerf = new FIPAPerformative(perf);
FIPA_AddressBook addresses = ((FIPA_AddressBook)context.getAddressBook());
String raddr = perf.getReceiver();
FIPA_AID_Address faddr = addresses.lookupAlias(raddr);
Vector recs = new Vector();
recs.addElement(faddr);
fPerf.setReceivers(recs);
String senderName = perf.getSender();
// Envelope perf.getEnvelope();
InetAddress ip = InetAddress.getLocalHost();
String localhost = hostname;
FIPA_AID_Address sender = new FIPA_AID_Address("(agent-identifier\n:name " + senderName + "@" + localhost + "\n:addresses (sequence " + getResponseAddress()+"))");
// sender.setName(perf.getSender());
fPerf.setSender(sender);
FIPA_PostMan postey =((Zeus_ACC_MailBox) mbox).getFIPA_PostMan();
postey.push(fPerf);
// set sender?}
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* send a registration to the nameservers that we are using. <br>
* @param sender is the name of the alias to use
*/
protected void registerAlias(FIPA_AID_Address sender) {
System.out.println("In register 1");
String name = sender.getName()+sender.getHost();
AddressBook addressBook = context.getAddressBook();
for(int i = 0; i < context.nameservers().size(); i++ ) {
String key = sender.setAlias(name);
Address addr = (Address)context.nameservers().elementAt(i);
addressBook.add(addr);
Performative msg = new Performative("request");
msg.setReceiver(addr.getName());
msg.setReplyWith(key);
msg.setContent("register");
msg.setSender(key);
System.out.println("send message to nameserver");
mbox.sendMsg(msg);
System.out.println("done message");
}
}
/**
send a registration to the nameservers that we are using. <br>
@param sender is the name of the alias to use
*/
protected void registerAlias(FIPA_AID_Address address, String name) {
AddressBook addressBook = context.getAddressBook();
for(int i = 0; i < context.nameservers().size(); i++ ) {
String key = address.setAlias(name);
Address addr = (Address)context.nameservers().elementAt(i);
addressBook.add(addr);
Performative msg = new Performative("request");
msg.setReceiver(addr.getName());
msg.setReplyWith(key);
msg.setContent("register");
msg.setSender(key);
mbox.sendMsg(msg);
}
}
/**
send a registration to the nameservers that we are using. <br>
@param sender is the name of the alias to use
*/
protected void registerAlias(String name) {
AddressBook addressBook = context.getAddressBook();
for(int i = 0; i < context.nameservers().size(); i++ ) {
String key = name;
Address addr = (Address)context.nameservers().elementAt(i);
addressBook.add(addr);
Performative msg = new Performative("request");
msg.setReceiver(addr.getName());
msg.setReplyWith(key);
msg.setContent("register");
msg.setSender(key);
mbox.sendMsg(msg);
}
}
/**
* registerAgent is functionally identical to registerAlias, but
* is semantically slightly different because in the one we are using
* the agent name directly, while in the other we are trying to decouple
*/
public void registerAgent(FIPA_AID_Address address, String name) {
this.registerAlias(address,name);
}
protected void finalize() {
try {
if ( listenSocket != null ) listenSocket.close();
timeout = -1;
}
catch(IOException e) {
}
}
public Address getAddress() {
return address;
}
/**
pull something off the ACC message processing queue
*/
public String pop() {
return (String) msgQ.dequeue();
}
/**
* put something onto the ACC message processing queue
*/
public void push(String target) {
debug ("enqueueing message ");
msgQ.enqueue(target);
}
/**
* handle(String message) is called by the FIPA_97_Server which the init method of the Zeus_ACC_Server
* class creates it is used as an interface to unify and collate the information
* reception and processing for the ACC agent. <p>
* implements the FIPA_97_Handler interface <p>
* @param message - the message picked up from the fipa_97 transport
*/
public void handle(String message) {
// simply push this onto the message handling q.
push(message);
}
/**
* handle (FIPA.FipaMessage aMessage) is called by the FIPA_2000_server that the
* init method of this class creates.
* implements that FIPA_2000_Handler interface<p>
* ISSUES <br>
* ------ <br>
* Envelopes - what should we do???
*
* @param aMessage - the message in FIPA 2000 object (java/idl) format
* @see FIPA.FipaMessage
*/
public synchronized void handle(FIPA.FipaMessage aMessage) {
byte body [] = aMessage.messageBody;
String messageStr = new String(body);
push(messageStr);
}
/**
return a string of addresses that this server is listening on
*/
public String getResponseAddress() {
String httpAddress = httpServer.getResponseAddress();//"http://" + host + ":" + http2000Port + name
String iiop2000Address = twoThousand_Server.getResponseAddress(); //"corbaname::" + host + ":" +iiop2000Port + "/NameService/" name
String iiop97Address = ninetySeven_Server.getResponseAddress();//"iiop" + host + ":" + iiop97Port + name
String ior2000Address = twoThousand_Server.getIORAddress();
// removed corba addresses
String addressStr = new String(iiop2000Address +" " + httpAddress );
return (addressStr);
}
public void debug(String str) {
System.out.println ("Zeus ACC server>> " + str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -