Search in sources :

Example 1 with UnknownMessageException

use of org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException in project controller by opendaylight.

the class ActorContext method findPrimaryShardAsync.

public Future<PrimaryShardInfo> findPrimaryShardAsync(final String shardName) {
    Future<PrimaryShardInfo> ret = primaryShardInfoCache.getIfPresent(shardName);
    if (ret != null) {
        return ret;
    }
    Future<Object> future = executeOperationAsync(shardManager, new FindPrimary(shardName, true), shardInitializationTimeout);
    return future.transform(new Mapper<Object, PrimaryShardInfo>() {

        @Override
        public PrimaryShardInfo checkedApply(Object response) throws UnknownMessageException {
            if (response instanceof RemotePrimaryShardFound) {
                LOG.debug("findPrimaryShardAsync received: {}", response);
                RemotePrimaryShardFound found = (RemotePrimaryShardFound) response;
                return onPrimaryShardFound(shardName, found.getPrimaryPath(), found.getPrimaryVersion(), null);
            } else if (response instanceof LocalPrimaryShardFound) {
                LOG.debug("findPrimaryShardAsync received: {}", response);
                LocalPrimaryShardFound found = (LocalPrimaryShardFound) response;
                return onPrimaryShardFound(shardName, found.getPrimaryPath(), DataStoreVersions.CURRENT_VERSION, found.getLocalShardDataTree());
            } else if (response instanceof NotInitializedException) {
                throw (NotInitializedException) response;
            } else if (response instanceof PrimaryNotFoundException) {
                throw (PrimaryNotFoundException) response;
            } else if (response instanceof NoShardLeaderException) {
                throw (NoShardLeaderException) response;
            }
            throw new UnknownMessageException(String.format("FindPrimary returned unkown response: %s", response));
        }
    }, FIND_PRIMARY_FAILURE_TRANSFORMER, getClientDispatcher());
}
Also used : PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) UnknownMessageException(org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)

Aggregations

NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)1 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)1 PrimaryNotFoundException (org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException)1 UnknownMessageException (org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException)1 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)1 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)1 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)1 RemotePrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound)1