Java Code Examples for com.google.common.collect.Multimaps#synchronizedMultimap()

The following examples show how to use com.google.common.collect.Multimaps#synchronizedMultimap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebsocketHandler.java    From onboard with Apache License 2.0 6 votes vote down vote up
public void sendMessage(String userEmail, String message) {

        Multimap<String, WebSocketSession> syncMap = Multimaps.synchronizedMultimap(userPagesMap);
        Collection<WebSocketSession> mis = syncMap.get(userEmail);
        synchronized (syncMap) {
            if (mis != null) {
                Iterator<WebSocketSession> it = mis.iterator();
                while (it.hasNext()) {
                    WebSocketSession session = it.next();
                    try {
                        session.sendMessage(new TextMessage(message));
                    } catch (Exception e) {
                        logger.info("The WebSocket connection has been closed: " + session.toString());
                    }

                }
            }
        }

    }
 
Example 2
Source File: WebSocketServiceImpl.java    From onboard with Apache License 2.0 6 votes vote down vote up
@Override
public void broadcastOne(String user, String message) {
    Multimap<String, MessageInbound> syncMap = Multimaps.synchronizedMultimap(userPagesMap);
    Collection<MessageInbound> mis = syncMap.get(user);
    synchronized (syncMap) {
        if (mis != null) {
            Iterator<MessageInbound> it = mis.iterator();
            while (it.hasNext()) {
                MessageInbound inbound = it.next();
                try {
                    sendToPage(inbound, message);
                } catch (IOException e) {
                    // userPagesMap.remove(user, inbound);
                    logger.info("The WebSocket connection has been closed: " + inbound.toString());
                }

            }
        }
    }
}
 
Example 3
Source File: QueryStatsDClient.java    From datawave with Apache License 2.0 5 votes vote down vote up
public QueryStatsDClient(String queryId, String host, int port, int maxCacheSize) {
    this.queryId = queryId;
    this.host = host;
    this.port = port;
    this.maxCacheSize = maxCacheSize;
    Multimap<String,Long> temp = HashMultimap.create();
    this.timings = Multimaps.synchronizedMultimap(temp);
    this.prefix = queryId + ".dwquery.";
}
 
Example 4
Source File: JcloudsRebindStubTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
    super.setUp();
    mgmts = Lists.newCopyOnWriteArrayList(ImmutableList.<ManagementContext>of(origManagementContext));
    machines = Multimaps.synchronizedMultimap(ArrayListMultimap.<ManagementContext, JcloudsSshMachineLocation>create());
}
 
Example 5
Source File: JcloudsRebindStubUnitTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
    super.setUp();
    RecordingSshTool.clear();
    RecordingWinRmTool.clear();
    mgmts = Lists.newCopyOnWriteArrayList(ImmutableList.<ManagementContext>of(origManagementContext));
    machines = Multimaps.synchronizedMultimap(ArrayListMultimap.<ManagementContext, JcloudsSshMachineLocation>create());
}
 
Example 6
Source File: ConfigurationManager.java    From ja-micro with Apache License 2.0 4 votes vote down vote up
@Inject
public ConfigurationManager(ServiceProperties props) {
    this.serviceProps = props;
    this.callbackListeners = Multimaps.synchronizedMultimap(ArrayListMultimap.create());
    this.lastProperties = new HashMap<>(props.getAllProperties());
}
 
Example 7
Source File: ElectionRegistry.java    From twill with Apache License 2.0 4 votes vote down vote up
public ElectionRegistry(ZKClient zkClient) {
  this.zkClient = zkClient;
  Multimap<String, LeaderElection> multimap = HashMultimap.create();
  this.registry = Multimaps.synchronizedMultimap(multimap);
}
 
Example 8
Source File: WebSocketRegistryImpl.java    From purplejs with Apache License 2.0 4 votes vote down vote up
public WebSocketRegistryImpl()
{
    this.idToSession = Maps.newConcurrentMap();
    this.groupToId = Multimaps.synchronizedMultimap( HashMultimap.create() );
}
 
Example 9
Source File: MemoryNotificationRegistry.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Inject
    public MemoryNotificationRegistry(ZonedDateTimeProvider zonedDateTimeProvider) {
        this.zonedDateTimeProvider = zonedDateTimeProvider;
        this.registrations = Multimaps.synchronizedMultimap(HashMultimap.create());
}