use of dmg.cells.network.PingMessage in project dcache by dCache.
the class WebCollectorV3 method sendPing.
private void sendPing(CellAddressCore address) {
LOGGER.debug("Sending ping to : {}", address);
sendMessage(new CellMessage(address, new PingMessage()));
}
use of dmg.cells.network.PingMessage in project dcache by dCache.
the class WebCollectorV3 method messageArrived.
@Override
public void messageArrived(CellMessage message) {
Object reply = message.getMessageObject();
int modified = 0;
if (reply instanceof LoginBrokerInfo) {
LoginBrokerInfo brokerInfo = (LoginBrokerInfo) reply;
synchronized (_infoLock) {
LOGGER.debug("Login broker reports: {}@{}", brokerInfo.getCellName(), brokerInfo.getDomainName());
if (addQuery(new CellAddressCore(brokerInfo.getCellName(), brokerInfo.getDomainName()))) {
modified++;
}
}
} else if (reply instanceof PingMessage) {
synchronized (_infoLock) {
addQuery(message.getSourceAddress());
}
} else {
CellPath path = message.getSourcePath();
CellAddressCore address = path.getSourceAddress();
CellQueryInfo info;
synchronized (_infoLock) {
info = _infoMap.get(address);
if (info == null) {
// We may have registered the cell as a well known cell
info = _infoMap.get(new CellAddressCore(address.getCellName()));
if (info == null) {
LOGGER.info("Unexpected reply arrived from: {}", path);
return;
}
}
}
if (reply instanceof CellInfo) {
LOGGER.debug("CellInfo: {}", ((CellInfo) reply).getCellName());
info.infoArrived((CellInfo) reply);
}
if (reply instanceof PoolManagerCellInfo) {
Set<CellAddressCore> pools = ((PoolManagerCellInfo) reply).getPoolCells();
synchronized (_infoLock) {
for (CellAddressCore pool : pools) {
if (addQuery(pool)) {
modified++;
}
}
}
}
}
_sleepHandler.topologyChanged(modified > 0);
}
use of dmg.cells.network.PingMessage in project dcache by dCache.
the class CellShell method _waitForCell.
private String _waitForCell(String cellName, int waitTime, int check, String command) throws CommandException {
if (check <= 4) {
check = 5;
}
CellPath destination = new CellPath(cellName);
long finish = System.currentTimeMillis() + (waitTime * 1000);
CellMessage answer;
Serializable message = (command == null) ? new PingMessage() : command;
Object o;
boolean noRoute;
while (true) {
noRoute = false;
answer = null;
try {
_log.warn("waitForCell : Sending request");
answer = _nucleus.sendAndWait(new CellMessage(destination, message), ((long) check) * 1000);
_log.warn("waitForCell : got {}", answer);
} catch (NoRouteToCellException e) {
noRoute = true;
} catch (ExecutionException ignored) {
} catch (InterruptedException e) {
throw new CommandException(66, "sendAndWait problem : " + e, e);
}
if ((answer != null) && ((o = answer.getMessageObject()) != null) && ((o instanceof PingMessage) || (o instanceof String))) {
break;
}
if ((waitTime == 0) || (finish > System.currentTimeMillis())) {
//
if ((!noRoute) && (answer == null)) {
continue;
}
//
try {
Thread.sleep(((long) check) * 1000);
} catch (InterruptedException ie) {
throw new CommandException(2, "Command Was interrupted");
}
continue;
}
throw new CommandException(1, "Command Timed Out");
}
return "";
}
use of dmg.cells.network.PingMessage in project dcache by dCache.
the class CellAdapter method messageArrived.
/**
* belongs to the Cell Interface. If this method is overwritten, the messageArrived(CellMessage
* cm) and the messageToForward(CellMessage) methods are never called.
*/
@Override
public void messageArrived(MessageEvent me) {
CellMessage msg = me.getMessage();
Serializable obj = msg.getMessageObject();
if (msg.isFinalDestination()) {
if (!msg.isReply() && msg.getLocalAge() > msg.getAdjustedTtl()) {
_log.warn("Discarding {} because its age of {} ms exceeds its time to live of {} ms.", (obj instanceof CharSequence) ? '\'' + Ascii.truncate((CharSequence) obj, 50, "...") + '\'' : obj.getClass().getSimpleName(), msg.getLocalAge(), msg.getAdjustedTtl());
return;
}
if (_useInterpreter && (!msg.isReply()) && ((obj instanceof String) || (obj instanceof AuthorizedString))) {
Serializable o;
UOID uoid = msg.getUOID();
EventLogger.deliverBegin(msg);
try {
o = executeLocalCommand(obj);
if (o == null) {
return;
}
} catch (CommandPanicException e) {
o = e;
_log.error("Command failed due to a bug, please contact support@dcache.org.", e);
} catch (CommandException ce) {
o = ce;
} finally {
EventLogger.deliverEnd(msg.getSession(), uoid);
}
if (o instanceof Reply) {
Reply reply = (Reply) o;
reply.deliver(this, msg);
} else {
msg.revertDirection();
msg.setMessageObject(o);
_nucleus.sendMessage(msg, true, true, true);
}
} else if ((obj instanceof PingMessage) && _answerPing) {
PingMessage ping = (PingMessage) obj;
if (ping.isWayBack()) {
messageArrived(msg);
return;
}
ping.setWayBack();
ping.setOutboundPath(msg.getSourcePath());
msg.revertDirection();
_nucleus.sendMessage(msg, true, true, true);
} else {
UOID uoid = msg.getUOID();
EventLogger.deliverBegin(msg);
try {
messageArrived(msg);
} finally {
EventLogger.deliverEnd(msg.getSession(), uoid);
}
}
} else if (obj instanceof PingMessage) {
_nucleus.sendMessage(msg, true, true, true);
} else {
UOID uoid = msg.getUOID();
EventLogger.deliverBegin(msg);
try {
messageToForward(msg);
} finally {
EventLogger.deliverEnd(msg.getSession(), uoid);
}
}
}
Aggregations