Search in sources :

Example 1 with PingMessage

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()));
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage) PingMessage(dmg.cells.network.PingMessage)

Example 2 with 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);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) CellAddressCore(dmg.cells.nucleus.CellAddressCore) PoolManagerCellInfo(diskCacheV111.poolManager.PoolManagerCellInfo) HashSet(java.util.HashSet) Set(java.util.Set) PoolCellInfo(diskCacheV111.pools.PoolCellInfo) PoolManagerCellInfo(diskCacheV111.poolManager.PoolManagerCellInfo) CellInfo(dmg.cells.nucleus.CellInfo) PingMessage(dmg.cells.network.PingMessage) LoginBrokerInfo(dmg.cells.services.login.LoginBrokerInfo)

Example 3 with PingMessage

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 "";
}
Also used : Serializable(java.io.Serializable) CommandException(dmg.util.CommandException) ExecutionException(java.util.concurrent.ExecutionException) PingMessage(dmg.cells.network.PingMessage)

Example 4 with PingMessage

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);
        }
    }
}
Also used : Serializable(java.io.Serializable) AuthorizedString(dmg.util.AuthorizedString) AuthorizedString(dmg.util.AuthorizedString) CommandException(dmg.util.CommandException) PingMessage(dmg.cells.network.PingMessage) CommandPanicException(dmg.util.CommandPanicException)

Aggregations

PingMessage (dmg.cells.network.PingMessage)4 CommandException (dmg.util.CommandException)2 Serializable (java.io.Serializable)2 PoolManagerCellInfo (diskCacheV111.poolManager.PoolManagerCellInfo)1 PoolCellInfo (diskCacheV111.pools.PoolCellInfo)1 CellAddressCore (dmg.cells.nucleus.CellAddressCore)1 CellInfo (dmg.cells.nucleus.CellInfo)1 CellMessage (dmg.cells.nucleus.CellMessage)1 CellPath (dmg.cells.nucleus.CellPath)1 LoginBrokerInfo (dmg.cells.services.login.LoginBrokerInfo)1 AuthorizedString (dmg.util.AuthorizedString)1 CommandPanicException (dmg.util.CommandPanicException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1