IIOPPrimaryToContactInfoImplpublic class IIOPPrimaryToContactInfoImpl extends Object implements com.sun.corba.ee.spi.transport.IIOPPrimaryToContactInfoThis is the "sticky manager" - based on the 7.1 EE concept. |
Fields Summary |
---|
private static Logger | _logger | public final String | baseMsg | private Map | map | private boolean | debugChecked | private boolean | debug |
Constructors Summary |
---|
public IIOPPrimaryToContactInfoImpl()
map = new HashMap();
debugChecked = false;
debug = false;
|
Methods Summary |
---|
private void | dprint(java.lang.String msg)
/*
ORBUtility.dprint("IIOPPrimaryToContactInfoImpl", msg);
*/
_logger.log(Level.FINE, msg);
| private java.lang.String | formatKeyPreviousList(java.lang.Object key, com.sun.corba.ee.pept.transport.ContactInfo previous, java.util.List list)
String result =
"\n key : " + key
+ "\n previous: " + previous
+ "\n list:";
Iterator i = list.iterator();
int count = 1;
while (i.hasNext()) {
result += "\n " + count++ + " " + i.next();
}
return result;
| private java.lang.String | formatMap(java.util.Map map)
String result = "";
synchronized (map) {
Iterator i = map.entrySet().iterator();
if (! i.hasNext()) {
return "empty";
}
while (i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
result +=
"\n key : " + entry.getKey()
+ "\n value: " + entry.getValue()
+ "\n";
}
}
return result;
| private java.lang.Object | getKey(com.sun.corba.ee.pept.transport.ContactInfo contactInfo)
if (((SocketInfo)contactInfo).getPort() == 0) {
// When CSIv2 is used the primary will have a zero port.
// Therefore type/host/port will NOT be unique.
// So use the entire IOR for the key in that case.
return ((CorbaContactInfoList)contactInfo.getContactInfoList())
.getEffectiveTargetIOR();
} else {
return contactInfo;
}
| public synchronized boolean | hasNext(com.sun.corba.ee.pept.transport.ContactInfo primary, com.sun.corba.ee.pept.transport.ContactInfo previous, java.util.List contactInfos)
try {
if (! debugChecked) {
debugChecked = true;
debug = ((ORB)primary.getBroker()).transportDebugFlag
|| _logger.isLoggable(Level.FINE);
}
if (debug) {
dprint(".hasNext->: "
+ formatKeyPreviousList(getKey(primary),
previous,
contactInfos));
}
boolean result;
if (previous == null) {
result = true;
} else {
int previousIndex = contactInfos.indexOf(previous);
int contactInfosSize = contactInfos.size();
if (debug) {
dprint(".hasNext: "
+ previousIndex + " " + contactInfosSize);
}
if (previousIndex < 0) {
// This SHOULD not happen.
// It would only happen if the previous is NOT
// found in the current list of contactInfos.
RuntimeException rte = new RuntimeException(
"Problem in " + baseMsg + ".hasNext: previousIndex: "
+ previousIndex);
_logger.log(Level.SEVERE,
"Problem in " + baseMsg + ".hasNext: previousIndex: "
+ previousIndex, rte);
throw rte;
} else {
// Since this is a retry, ensure that there is a following
// ContactInfo for .next
result = (contactInfosSize - 1) > previousIndex;
}
}
if (debug) {
dprint(".hasNext<-: " + result);
}
return result;
} catch (Throwable t) {
_logger.log(Level.WARNING,
"Problem in " + baseMsg + ".hasNext",
t);
RuntimeException rte =
new RuntimeException(baseMsg + ".hasNext error");
rte.initCause(t);
throw rte;
}
| public synchronized com.sun.corba.ee.pept.transport.ContactInfo | next(com.sun.corba.ee.pept.transport.ContactInfo primary, com.sun.corba.ee.pept.transport.ContactInfo previous, java.util.List contactInfos)
try {
String debugMsg = null;
if (debug) {
debugMsg = "";
dprint(".next->: "
+ formatKeyPreviousList(getKey(primary),
previous,
contactInfos));
dprint(".next: map: " + formatMap(map));
}
Object result = null;
if (previous == null) {
// This is NOT a retry.
result = map.get(getKey(primary));
if (result == null) {
if (debug) {
debugMsg = ".next<-: initialize map: ";
}
// NOTE: do not map primary to primary.
// In case of local transport we NEVER use primary.
result = contactInfos.get(0);
map.put(getKey(primary), result);
} else {
if (debug) {
dprint(".next: primary mapped to: " + result);
}
int position = contactInfos.indexOf(result);
if (position == -1) {
// It is possible that communication to the key
// took place on SharedCDR, then a corbaloc to
// same location uses a SocketOrChannelContactInfo
// and vice versa.
if (debug) {
dprint(".next: cannot find mapped entry in current list. Removing mapped entry and trying .next again.");
}
reset(primary);
return next(primary, previous, contactInfos);
}
// NOTE: This step is critical. You do NOT want to
// return contact info from the map. You want to find
// it, as a SocketInfo, in the current list, and then
// return that ContactInfo. Otherwise you will potentially
// return a ContactInfo pointing to an incorrect IOR.
result = contactInfos.get(position);
if (debug) {
debugMsg = ".next<-: mapped: ";
}
}
} else {
// This is a retry.
// If previous is last element then .next is not called
// because hasNext will return false.
result = contactInfos.get(contactInfos.indexOf(previous) + 1);
map.put(getKey(primary), result);
_logger.log(Level.INFO, "IIOP failover to: " + result);
if (debug) {
debugMsg = ".next<-: update map: "
+ " " + contactInfos.indexOf(previous)
+ " " + contactInfos.size() + " ";
}
}
if (debug) {
dprint(debugMsg + result);
}
return (ContactInfo) result;
} catch (Throwable t) {
_logger.log(Level.WARNING,
"Problem in " + baseMsg + ".next",
t);
RuntimeException rte =
new RuntimeException(baseMsg + ".next error");
rte.initCause(t);
throw rte;
}
| public synchronized void | reset(com.sun.corba.ee.pept.transport.ContactInfo primary)
try {
if (debug) {
dprint(".reset: " + getKey(primary));
}
map.remove(getKey(primary));
} catch (Throwable t) {
_logger.log(Level.WARNING,
"Problem in " + baseMsg + ".reset",
t);
RuntimeException rte =
new RuntimeException(baseMsg + ".reset error");
rte.initCause(t);
throw rte;
}
|
|