Example usage for java.util.function Consumer getClass

List of usage examples for java.util.function Consumer getClass

Introduction

In this page you can find the example usage for java.util.function Consumer getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:io.tilt.minka.business.impl.TransportlessLeaderShardContainer.java

@Override
public void setNewLeader(final NetworkShardID newLeader) {
    Validate.notNull(newLeader, "Cannot set a Null leader !");
    try {//from  w  w w .  j a  v a 2  s  . c om
        boolean firstLeader = lastLeaderShardId == null;
        if (!firstLeader && lastLeaderShardId.equals(newLeader)) {
            logger.info("{}: ({}) same Leader {} reelected, skipping observer notification",
                    getClass().getSimpleName(), myShardId, this.leaderShardId.getStringID());
            previousLeaders.add(leaderShardId);
        } else {
            logger.info("{}: ({}) Updating new Leader elected: {}", getClass().getSimpleName(), myShardId,
                    newLeader);
            if (!firstLeader) {
                previousLeaders.add(leaderShardId);
            }
            leaderShardId = newLeader;
            for (Consumer<NetworkShardID> o : this.observers) {
                logger.info("{}: ({}) Notifying observer: {}", getClass().getSimpleName(), myShardId,
                        o.getClass().getSimpleName());
                o.accept(this.leaderShardId);
            }
            lastLeaderShardId = newLeader;
        }
    } catch (Exception e) {
        logger.error("{}: ({}) LeaderShardContainer: unexpected error", getClass().getSimpleName(), myShardId,
                e);
    }
}

From source file:io.tilt.minka.spectator.NodeCacheable.java

protected <T> boolean createCache(final String prefix, final String name,
        final Consumer<MessageMetadata> consumer, final TreeCacheListener listener, final boolean fromTail,
        final long sinceTimestamp, final long retentionLapse) {

    TreeCache node = null;/*from w w w .j  a  v a2 s .  c  o  m*/
    try {
        final String nodepath = prefix + name;
        final CuratorFramework client = getClient();

        if (!isStarted()) {
            logger.error("{}: ({}) Cannot use Distributed utilities before setting Zookeeper connection",
                    getClass().getSimpleName(), getLogId());
            return false;
        }
        logger.info("{}: ({}) Caching changes on path: {} with listener:{}", getClass().getSimpleName(),
                getLogId(), nodepath, consumer.getClass().getSimpleName());
        node = new TreeCache(client, nodepath);
        node.getListenable().addListener(listener);
        add(name, new UserInstanceObject(node, consumer));
        // only to discard messages
        final Stat stat = client.checkExists().forPath(nodepath);
        if (stat != null && stat.getCtime() > 0 && listener instanceof PublishSubscribeQueue) {
            ((PublishSubscribeQueue) listener).readMessages(fromTail, getClient());
        }
        node.start();
        return true;
    } catch (Exception e) {
        if (isStarted()) {
            logger.error("{}: ({}), Unexpected while creating node cache: {} with consumer: {}",
                    getClass().getSimpleName(), getLogId(), name, consumer.getClass().getSimpleName(), e);
        } else {
            logger.error(
                    "{}: ({}), Zookeeper Disconection: Cancelling creating node cache: {} with consumer: {}",
                    getClass().getSimpleName(), getLogId(), name, consumer.getClass().getSimpleName(),
                    e.getMessage());
        }
        IOUtils.closeQuietly(node); // only if operation fails
    }
    return false;
}