Example usage for com.google.common.collect Multimaps synchronizedSetMultimap

List of usage examples for com.google.common.collect Multimaps synchronizedSetMultimap

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps synchronizedSetMultimap.

Prototype

public static <K, V> SetMultimap<K, V> synchronizedSetMultimap(SetMultimap<K, V> multimap) 

Source Link

Document

Returns a synchronized (thread-safe) SetMultimap backed by the specified multimap.

Usage

From source file:com.squid.kraken.v4.api.core.websocket.NotificationWebsocket.java

@OnOpen
public void onOpen(Session session) throws IOException, EncodeException {
    // check for an auth token
    String tokenId = null;//from w  ww .  j  ava2s.co  m
    String queryString = session.getQueryString();
    if (queryString != null) {
        Map<String, String> splitQuery = splitQuery(queryString);
        tokenId = splitQuery.get(ServiceUtils.TOKEN_PARAM);
    }
    // create a new context with a new session id
    String bouquetSessionId = UUID.randomUUID().toString();
    try {
        AppContext userContext = buildUserContext(tokenId, bouquetSessionId);
        // update the session
        session.getUserProperties().put("ctx", userContext);
        // keep this session
        sessions.add(session);
        Multimaps.synchronizedSetMultimap(sessionsByToken).put(tokenId, session);
        logger.info("Session added with ID : " + session.getId() + " uuid : " + bouquetSessionId);
    } catch (TokenExpiredException | InvalidCredentialsAPIException e) {
        // send a logout message
        logger.info("Invalid or expired token : " + tokenId);
        session.getBasicRemote().sendObject(new SessionMessage(bouquetSessionId, true, true));
    }
}

From source file:org.apache.zookeeper.MockZooKeeper.java

private void init(ExecutorService executor) {
    tree = Maps.newTreeMap();//from  w w  w . jav  a  2 s .  c om
    if (executor != null) {
        this.executor = executor;
    } else {
        this.executor = Executors.newFixedThreadPool(1, new DefaultThreadFactory("mock-zookeeper"));
    }
    SetMultimap<String, Watcher> w = HashMultimap.create();
    watchers = Multimaps.synchronizedSetMultimap(w);
    stopped = false;
    stepsToFail = new AtomicInteger(-1);
    failReturnCode = KeeperException.Code.OK;
}

From source file:org.onosproject.sdnip.Router.java

/**
 * Class constructor.//from w w  w  . ja  v a2 s.c om
 *
 * @param appId             the application ID
 * @param intentSynchronizer the intent synchronizer
 * @param configService     the configuration service
 * @param interfaceService  the interface service
 * @param hostService       the host service
 */
public Router(ApplicationId appId, IntentSynchronizer intentSynchronizer,
        SdnIpConfigurationService configService, InterfaceService interfaceService, HostService hostService) {
    this.appId = appId;
    this.intentSynchronizer = intentSynchronizer;
    this.configService = configService;
    this.interfaceService = interfaceService;
    this.hostService = hostService;

    this.hostListener = new InternalHostListener();

    ribTable4 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    ribTable6 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    routeUpdatesQueue = new LinkedBlockingQueue<>();
    routesWaitingOnArp = Multimaps.synchronizedSetMultimap(HashMultimap.<IpAddress, RouteEntry>create());
    ip2Mac = new ConcurrentHashMap<>();

    bgpUpdatesExecutor = Executors
            .newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("sdnip-bgp-updates-%d").build());
}

From source file:org.restcomm.media.control.mgcp.endpoint.GenericMgcpEndpoint.java

public GenericMgcpEndpoint(EndpointIdentifier endpointId, MgcpConnectionProvider connectionProvider,
        MediaGroup mediaGroup) {//from  ww w  .j  a v  a  2s.  c om
    // MGCP Components
    this.connectionProvider = connectionProvider;

    // Endpoint Properties
    this.endpointId = endpointId;
    this.connections = new ConcurrentHashMap<>(5);

    // Endpoint State
    this.active = new AtomicBoolean(false);

    // Media Components
    this.mediaGroup = mediaGroup;

    // Events and Signals
    this.notifiedEntity = new NotifiedEntity();
    this.signals = new ConcurrentHashMap<>(5);
    this.requestedEndpointEvents = EMPTY_ENDPOINT_EVENTS;
    this.requestedConnectionEvents = Multimaps
            .synchronizedSetMultimap(HashMultimap.<Integer, MgcpRequestedEvent>create());

    // Observers
    this.endpointObservers = Sets.newConcurrentHashSet();
    this.messageObservers = Sets.newConcurrentHashSet();
}

From source file:org.onosproject.routing.impl.DefaultRouter.java

@Activate
public void activate() {
    ribTable4 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    ribTable6 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());

    routesWaitingOnArp = Multimaps.synchronizedSetMultimap(HashMultimap.create());

    coreService.registerApplication(ROUTER_APP_ID);

    bgpUpdatesExecutor = Executors
            .newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("rib-updates-%d").build());
}

From source file:org.onosproject.routing.impl.Router.java

@Activate
public void activate() {
    ribTable4 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    ribTable6 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());

    routesWaitingOnArp = Multimaps.synchronizedSetMultimap(HashMultimap.<IpAddress, RouteEntry>create());

    coreService.registerApplication(ROUTER_APP_ID);

    bgpUpdatesExecutor = Executors
            .newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("sdnip-bgp-updates-%d").build());
}

From source file:org.opendaylight.atrium.routingservice.impl.Router.java

@Override
public void onSessionInitiated(ProviderContext session) {
    LOG.info("Router Session Initiated");
    ribTable4 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    ribTable6 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());

    routesWaitingOnArp = Multimaps.synchronizedSetMultimap(HashMultimap.<IpAddress, RouteEntry>create());

    bgpUpdatesExecutor = Executors
            .newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("atrium-bgp-updates-%d").build());

}

From source file:com.bigdata.dastor.service.StorageService.java

public StorageService() {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {//  w  w  w .  j a va 2 s  .  c o m
        mbs.registerMBean(this, new ObjectName("com.bigdata.dastor.service:type=StorageService"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    bootstrapSet = Multimaps.synchronizedSetMultimap(HashMultimap.<InetAddress, String>create());

    /* register the verb handlers */
    MessagingService.instance.registerVerbHandlers(Verb.BINARY, new BinaryVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.MUTATION, new RowMutationVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.READ_REPAIR, new ReadRepairVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.READ, new ReadVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.RANGE_SLICE, new RangeSliceVerbHandler());
    // see BootStrapper for a summary of how the bootstrap verbs interact
    MessagingService.instance.registerVerbHandlers(Verb.BOOTSTRAP_TOKEN,
            new BootStrapper.BootstrapTokenVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.STREAM_REQUEST, new StreamRequestVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.STREAM_INITIATE, new StreamInitiateVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.STREAM_INITIATE_DONE,
            new StreamInitiateDoneVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.STREAM_FINISHED, new StreamFinishedVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.READ_RESPONSE, new ResponseVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.TREE_REQUEST, new TreeRequestVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.TREE_RESPONSE,
            new AntiEntropyService.TreeResponseVerbHandler());

    MessagingService.instance.registerVerbHandlers(Verb.JOIN, new GossiperJoinVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.GOSSIP_DIGEST_SYN, new GossipDigestSynVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.GOSSIP_DIGEST_ACK, new GossipDigestAckVerbHandler());
    MessagingService.instance.registerVerbHandlers(Verb.GOSSIP_DIGEST_ACK2, new GossipDigestAck2VerbHandler());

    replicationStrategies = new HashMap<String, AbstractReplicationStrategy>();
    for (String table : DatabaseDescriptor.getNonSystemTables()) {
        AbstractReplicationStrategy strat = getReplicationStrategy(tokenMetadata_, table);
        replicationStrategies.put(table, strat);
    }
    replicationStrategies = Collections.unmodifiableMap(replicationStrategies);

    // spin up the streaming serivice so it is available for jmx tools.
    if (StreamingService.instance == null)
        throw new RuntimeException("Streaming service is unavailable.");
}

From source file:org.opendaylight.atrium.routingservice.impl.RibManager.java

@Override
public void onSessionInitiated(ProviderContext session) {
    LOG.info("Router Session Initiated");
    routesWaitingOnArp = Multimaps.synchronizedSetMultimap(HashMultimap.<AtriumIpAddress, RouteEntry>create());
    ribTable4 = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    bgpUpdatesExecutor = Executors
            .newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("atrium-bgp-updates-%d").build());
}

From source file:com.zimbra.cs.mailbox.MailboxIndex.java

/**
 * Returns the index deferred item count for the types.
 *
 * @param types item types, empty set means all types
 * @return index deferred count/*from ww w  .j av  a2s.c  om*/
 */
private int getDeferredCount(Set<MailItem.Type> types) {
    SetMultimap<MailItem.Type, Integer> ids;
    try {
        ids = Multimaps.synchronizedSetMultimap(getDeferredIds());
    } catch (ServiceException e) {
        ZimbraLog.index.error("Failed to query deferred IDs", e);
        return 0;
    }

    if (ids == null || ids.isEmpty()) {
        return 0;
    } else if (types.isEmpty()) {
        return ids.size();
    } else {
        int total = 0;
        for (MailItem.Type type : types) {
            total += ids.get(type).size();
        }
        return total;
    }
}