Methods Summary |
---|
public static Link | getLink(java.lang.String name)
if (!linksReceived) {
throw new IllegalStateException();
}
Link link = (Link)links.get(name);
if (link == null) {
throw new IllegalArgumentException();
}
return link;
|
public static void | putLink(java.lang.String linkName, Link link)
if (linksSent) {
throw new IllegalStateException();
}
if (linkName == null || link == null) {
throw new IllegalArgumentException();
}
links.put(linkName, link);
|
public static void | receiveLinks(Link receiveLink)
/**
* Arguments sanity checks
*/
if (receiveLink == null) {
throw new IllegalArgumentException();
}
if (linksReceived) {
throw new IllegalStateException();
}
// start session
LinkMessage startSessionMsg = receiveLink.receive();
String startSessionStr = startSessionMsg.extractString();
if (!startSessionStr.equals(START_SESSION_STR)) {
throw new IllegalStateException();
}
Hashtable l = new Hashtable();
while (true) {
LinkMessage strMsg = receiveLink.receive();
String str = strMsg.extractString();
if (str.equals(END_SESSION_STR)) {
break;
}
String linkName = str;
LinkMessage linkMsg = receiveLink.receive();
Link link = linkMsg.extractLink();
if (!link.isOpen()) {
throw new IllegalStateException();
}
l.put(linkName, link);
}
links = l;
linksReceived = true;
|
public static void | sendLinks(Link sendLink)
/**
* Arguments sanity checks
*/
if (sendLink == null) {
throw new IllegalArgumentException();
}
if (linksSent) {
throw new IllegalStateException();
}
Enumeration linksEnum = links.elements();
while (linksEnum.hasMoreElements()) {
Link link = null;
try {
link = (Link)linksEnum.nextElement();
} catch (ClassCastException e) {
throw new IllegalStateException();
}
if (!link.isOpen()) {
throw new IllegalStateException();
}
}
// start session
LinkMessage startSessionMsg = LinkMessage.newStringMessage(
START_SESSION_STR);
sendLink.send(startSessionMsg);
// send named links
Enumeration linkNamesEnum = links.keys();
while (linkNamesEnum.hasMoreElements()) {
String linkName = (String)linkNamesEnum.nextElement();
Link link = (Link)links.get(linkName);
if (link == null) {
throw new IllegalStateException();
}
LinkMessage linkNameMsg = LinkMessage.newStringMessage(linkName);
sendLink.send(linkNameMsg);
LinkMessage linkMsg = LinkMessage.newLinkMessage(link);
sendLink.send(linkMsg);
}
// end session
LinkMessage endSessionMsg = LinkMessage.newStringMessage(
END_SESSION_STR);
sendLink.send(endSessionMsg);
linksSent = true;
|