Search in sources :

Example 1 with JGroupsAddressCache.fromJGroupsAddress

use of org.infinispan.remoting.transport.jgroups.JGroupsAddressCache.fromJGroupsAddress in project infinispan by infinispan.

the class JGroupsTransport method backupRemotely.

@Override
public <O> XSiteResponse<O> backupRemotely(XSiteBackup backup, XSiteReplicateCommand<O> rpcCommand) {
    assert !localSite.equals(backup.getSiteName()) : "sending to local site";
    if (unreachableSites.containsKey(backup.getSiteName())) {
        // fail fast if we have thread handling a SITE_UNREACHABLE event.
        return new SiteUnreachableXSiteResponse<>(backup, timeService);
    }
    Address recipient = JGroupsAddressCache.fromJGroupsAddress(new SiteMaster(backup.getSiteName()));
    long requestId = requests.newRequestId();
    logRequest(requestId, rpcCommand, recipient, "backup");
    SingleSiteRequest<ValidResponse> request = new SingleSiteRequest<>(SingleResponseCollector.validOnly(), requestId, requests, backup.getSiteName());
    addRequest(request);
    DeliverOrder order = backup.isSync() ? DeliverOrder.NONE : DeliverOrder.PER_SENDER;
    long timeout = backup.getTimeout();
    XSiteResponseImpl<O> xSiteResponse = new XSiteResponseImpl<>(timeService, backup);
    try {
        sendCommand(recipient, rpcCommand, request.getRequestId(), order, false, false);
        if (timeout > 0) {
            request.setTimeout(timeoutExecutor, timeout, TimeUnit.MILLISECONDS);
        }
        request.whenComplete(xSiteResponse);
    } catch (Throwable t) {
        request.cancel(true);
        xSiteResponse.completeExceptionally(t);
    }
    return xSiteResponse;
}
Also used : PhysicalAddress(org.jgroups.PhysicalAddress) SiteAddress(org.jgroups.protocols.relay.SiteAddress) JGroupsAddressCache.fromJGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddressCache.fromJGroupsAddress) Address(org.infinispan.remoting.transport.Address) ValidResponse(org.infinispan.remoting.responses.ValidResponse) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) SiteMaster(org.jgroups.protocols.relay.SiteMaster) SiteUnreachableXSiteResponse(org.infinispan.remoting.transport.impl.SiteUnreachableXSiteResponse) XSiteResponseImpl(org.infinispan.remoting.transport.impl.XSiteResponseImpl)

Example 2 with JGroupsAddressCache.fromJGroupsAddress

use of org.infinispan.remoting.transport.jgroups.JGroupsAddressCache.fromJGroupsAddress in project infinispan by infinispan.

the class JGroupsTransport method backupRemotely.

@Override
public BackupResponse backupRemotely(Collection<XSiteBackup> backups, XSiteReplicateCommand command) {
    if (log.isTraceEnabled())
        log.tracef("About to send to backups %s, command %s", backups, command);
    Map<XSiteBackup, CompletableFuture<ValidResponse>> backupCalls = new HashMap<>(backups.size());
    for (XSiteBackup xsb : backups) {
        assert !localSite.equals(xsb.getSiteName()) : "sending to local site";
        Address recipient = JGroupsAddressCache.fromJGroupsAddress(new SiteMaster(xsb.getSiteName()));
        long requestId = requests.newRequestId();
        logRequest(requestId, command, recipient, "backup");
        SingleSiteRequest<ValidResponse> request = new SingleSiteRequest<>(SingleResponseCollector.validOnly(), requestId, requests, xsb.getSiteName());
        addRequest(request);
        backupCalls.put(xsb, request);
        DeliverOrder order = xsb.isSync() ? DeliverOrder.NONE : DeliverOrder.PER_SENDER;
        long timeout = xsb.getTimeout();
        try {
            sendCommand(recipient, command, request.getRequestId(), order, false, false);
            if (timeout > 0) {
                request.setTimeout(timeoutExecutor, timeout, TimeUnit.MILLISECONDS);
            }
        } catch (Throwable t) {
            request.cancel(true);
            throw t;
        }
    }
    return new JGroupsBackupResponse(backupCalls, timeService);
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) PhysicalAddress(org.jgroups.PhysicalAddress) SiteAddress(org.jgroups.protocols.relay.SiteAddress) JGroupsAddressCache.fromJGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddressCache.fromJGroupsAddress) Address(org.infinispan.remoting.transport.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ValidResponse(org.infinispan.remoting.responses.ValidResponse) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) CompletableFuture(java.util.concurrent.CompletableFuture) SiteMaster(org.jgroups.protocols.relay.SiteMaster)

Aggregations

DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)2 ValidResponse (org.infinispan.remoting.responses.ValidResponse)2 Address (org.infinispan.remoting.transport.Address)2 JGroupsAddressCache.fromJGroupsAddress (org.infinispan.remoting.transport.jgroups.JGroupsAddressCache.fromJGroupsAddress)2 PhysicalAddress (org.jgroups.PhysicalAddress)2 SiteAddress (org.jgroups.protocols.relay.SiteAddress)2 SiteMaster (org.jgroups.protocols.relay.SiteMaster)2 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SiteUnreachableXSiteResponse (org.infinispan.remoting.transport.impl.SiteUnreachableXSiteResponse)1 XSiteResponseImpl (org.infinispan.remoting.transport.impl.XSiteResponseImpl)1 XSiteBackup (org.infinispan.xsite.XSiteBackup)1