Java Code Examples for java.util.concurrent.ConcurrentHashMap.newKeySet()

The following are Jave code examples for showing how to use newKeySet() of the java.util.concurrent.ConcurrentHashMap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: L2J-Global   File: MobGroup.java   View Source Code Vote up 6 votes
public Set<L2ControllableMobInstance> getMobs()
{
	if (_mobs == null)
	{
		_mobs = ConcurrentHashMap.newKeySet();
	}
	
	return _mobs;
}
 
Example 2
Project: message-broker   File: QueueHandler.java   View Source Code Vote up 6 votes
private QueueHandler(Queue queue) {
    this.queue = queue;
    unmodifiableQueueView = new UnmodifiableQueueWrapper(queue);
    // TODO: take message count from queue configuration
    this.redeliveryQueue = new MemQueueImpl(queue.getName(), 1000, false);
    this.consumers = ConcurrentHashMap.newKeySet();
    consumerIterator = new CyclicConsumerIterator();

}
 
Example 3
Project: wamp2spring   File: Procedure.java   View Source Code Vote up 6 votes
public Procedure(RegisterMessage registerMessage, long registrationId,
		boolean isDealerCallerIdentificationFeatureEnabled) {
	this.procedure = registerMessage.getProcedure();
	this.webSocketSessionId = registerMessage.getWebSocketSessionId();
	if (isDealerCallerIdentificationFeatureEnabled) {
		this.discloseCaller = registerMessage.isDiscloseCaller();
	}
	else {
		this.discloseCaller = false;
	}
	this.registrationId = registrationId;
	this.pendingInvocations = ConcurrentHashMap.newKeySet();
}
 
Example 4
Project: wamp2spring   File: Subscription.java   View Source Code Vote up 6 votes
Subscription(String topic, MatchPolicy matchPolicy, long subscriptionId) {
	this.createdTimeMillis = System.currentTimeMillis();

	this.topicMatch = new DestinationMatch(topic, matchPolicy);

	this.subscriptionId = subscriptionId;
	this.subscribers = ConcurrentHashMap.newKeySet();
}
 
Example 5
Project: L2J-Global   File: CharEffectList.java   View Source Code Vote up 6 votes
/**
 * Adds abnormal types to the blocked buff slot set.
 * @param blockedAbnormalTypes the blocked buff slot set to add
 */
public void addBlockedAbnormalTypes(Set<AbnormalType> blockedAbnormalTypes)
{
	if (_blockedAbnormalTypes == null)
	{
		synchronized (this)
		{
			if (_blockedAbnormalTypes == null)
			{
				_blockedAbnormalTypes = ConcurrentHashMap.newKeySet(blockedAbnormalTypes.size());
			}
		}
	}
	_blockedAbnormalTypes.addAll(blockedAbnormalTypes);
}
 
Example 6
Project: lams   File: PresenceWebsocketServer.java   View Source Code Vote up 6 votes
/**
    * Registeres the Learner for processing by SendWorker.
    */
   @OnOpen
   public void registerUser(Session session) throws IOException {
Long lessonId = Long.valueOf(session.getRequestParameterMap().get(AttributeNames.PARAM_LESSON_ID).get(0));
Set<Websocket> sessionWebsockets = PresenceWebsocketServer.websockets.get(lessonId);
if (sessionWebsockets == null) {
    sessionWebsockets = ConcurrentHashMap.newKeySet();
    PresenceWebsocketServer.websockets.put(lessonId, sessionWebsockets);
}
Websocket websocket = new Websocket(session);
sessionWebsockets.add(websocket);

Roster roster = PresenceWebsocketServer.rosters.get(lessonId);
if (roster == null) {
    boolean imEnabled = Boolean.valueOf(session.getRequestParameterMap().get("imEnabled").get(0));
    // build a new roster object
    roster = new Roster(lessonId, imEnabled);
    PresenceWebsocketServer.rosters.put(lessonId, roster);
}

new Thread(() -> {
    try {
	// websocket communication bypasses standard HTTP filters, so Hibernate session needs to be initialised manually
	HibernateSessionManager.openSession();
	SendWorker.send(lessonId, websocket.nickName);
    } finally {
	HibernateSessionManager.closeSession();
    }
}).start();

if (PresenceWebsocketServer.log.isDebugEnabled()) {
    PresenceWebsocketServer.log
	    .debug("User " + websocket.nickName + " entered Presence Chat with lesson ID: " + lessonId);
}
   }
 
Example 7
Project: lams   File: LearningWebsocketServer.java   View Source Code Vote up 6 votes
/**
    * Registeres the Learner for processing by SendWorker.
    */
   @OnOpen
   public void registerUser(Session session) throws IOException {
Long toolSessionId = Long
	.valueOf(session.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
Set<Websocket> sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId);
if (sessionWebsockets == null) {
    sessionWebsockets = ConcurrentHashMap.newKeySet();
    LearningWebsocketServer.websockets.put(toolSessionId, sessionWebsockets);
}
final Set<Websocket> finalSessionWebsockets = sessionWebsockets;

String userName = session.getUserPrincipal().getName();
new Thread(() -> {
    try {
	// websocket communication bypasses standard HTTP filters, so Hibernate session needs to be initialised manually
	HibernateSessionManager.openSession();
	ChatUser chatUser = LearningWebsocketServer.getChatService().getUserByLoginNameAndSessionId(userName,
		toolSessionId);
	Websocket websocket = new Websocket(session, chatUser.getNickname(), chatUser.getUserId(), getPortraitId(chatUser.getUserId()));
	finalSessionWebsockets.add(websocket);

	// update the chat window immediatelly
	SendWorker.send(toolSessionId);

	if (LearningWebsocketServer.log.isDebugEnabled()) {
	    LearningWebsocketServer.log
		    .debug("User " + userName + " entered Chat with toolSessionId: " + toolSessionId);
	}
    } finally {
	HibernateSessionManager.closeSession();
    }
}).start();
   }
 
Example 8
Project: lams   File: LearningWebsocketServer.java   View Source Code Vote up 6 votes
/**
    * Registeres the Learner for processing by SendWorker.
    */
   @OnOpen
   public void registerUser(Session websocket) throws JSONException, IOException {
Long toolSessionId = Long
	.valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
Set<Session> sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId);
if (sessionWebsockets == null) {
    sessionWebsockets = ConcurrentHashMap.newKeySet();
    LearningWebsocketServer.websockets.put(toolSessionId, sessionWebsockets);

    Map<Long, Map<Long, Boolean>> sessionCache = new TreeMap<>();
    LearningWebsocketServer.cache.put(toolSessionId, sessionCache);
}
sessionWebsockets.add(websocket);

if (LearningWebsocketServer.log.isDebugEnabled()) {
    LearningWebsocketServer.log.debug("User " + websocket.getUserPrincipal().getName()
	    + " entered Scratchie with toolSessionId: " + toolSessionId);
}
   }
 
Example 9
Project: lams   File: LearningWebsocketServer.java   View Source Code Vote up 6 votes
/**
    * Registeres the Learner for processing by SendWorker.
    */
   @OnOpen
   public void registerUser(Session websocket) throws JSONException, IOException {
Long toolSessionId = Long
	.valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
Set<Session> sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId);
if (sessionWebsockets == null) {
    sessionWebsockets = ConcurrentHashMap.newKeySet();
    LearningWebsocketServer.websockets.put(toolSessionId, sessionWebsockets);
}
sessionWebsockets.add(websocket);

if (LearningWebsocketServer.log.isDebugEnabled()) {
    LearningWebsocketServer.log.debug("User " + websocket.getUserPrincipal().getName()
	    + " entered Scribe with toolSessionId: " + toolSessionId);
}

new Thread(() -> {
    try {
	HibernateSessionManager.openSession();
	SendWorker.send(toolSessionId, websocket);
    } catch (Exception e) {
	log.error("Error while sending messages", e);
    } finally {
	HibernateSessionManager.closeSession();
    }
}).start();
   }
 
Example 10
Project: swblocks-decisiontree   File: RuleChangeBuilderTest.java   View Source Code Vote up 6 votes
@Test
public void createsNewRule() {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = getRuleSetBuilder();

    final DriverCache cache = new DriverCache();
    final Set<ValueGroup> groups = ConcurrentHashMap.newKeySet();
    final ValueGroup group = new ValueGroup("CMEGroup", Arrays.asList("CME", "CBOT"));
    groups.add(group);
    RuleSetBuilder.addValueGroupsToDriverCache(cache, groups);

    ruleSetBuilder.with(RuleSetBuilder::setCache, cache);
    ruleSetBuilder.with(RuleSetBuilder::groups, groups);
    this.ruleSet = ruleSetBuilder.build();

    this.builder = RuleChangeBuilder.creator(this.ruleSet, new UUID(0, 9));
    this.builder.with(RuleChangeBuilder::input,
            Arrays.asList("VOICE", "CME", "ED", "UK", GroupDriver.VG_PREFIX + group.getId()));
    this.builder.with(RuleChangeBuilder::output, Collections.singletonMap("Rate", "2.0"));
    this.builder.with(RuleChangeBuilder::changeRange,
            new DateRange(NOW.minus(Period.ofWeeks(1)), NOW.plus(Period.ofWeeks(1))));
    final List<RuleChange> ruleChanges = this.builder.build();
    assertThat(ruleChanges, hasSize(1));

    final RuleChange change = ruleChanges.get(0);
    assertEquals(Type.NEW, change.getType());

    assertRuleChange(change, Type.NEW, null, new UUID(0, 9),
            new String[]{"VOICE", "CME", "ED", "UK", GroupDriver.VG_PREFIX + group.getId().toString()},
            Collections.singletonMap("Rate", "2.0"), NOW.minus(Period.ofWeeks(1)),
            NOW.plus(Period.ofWeeks(1)));

    final List<String> driverValues =
            Arrays.stream(change.getRule().getDrivers()).map(InputDriver::toString).collect(Collectors.toList());
    assertThat(driverValues, contains("VOICE", "CME", "ED", "UK", GroupDriver.VG_PREFIX + group.getId()));
}
 
Example 11
Project: L2J-Global   File: CharStatus.java   View Source Code Vote up 6 votes
/**
 * Return the list of L2Character that must be informed of HP/MP updates of this L2Character.<br>
 * <B><U>Concept</U>:</B><br>
 * Each L2Character owns a list called <B>_statusListener</B> that contains all L2PcInstance to inform of HP/MP updates.<br>
 * Players who must be informed are players that target this L2Character.<br>
 * When a RegenTask is in progress sever just need to go through this list to send Server->Client packet StatusUpdate.
 * @return The list of L2Character to inform or null if empty
 */
public final Set<L2Character> getStatusListener()
{
	if (_StatusListener == null)
	{
		_StatusListener = ConcurrentHashMap.newKeySet();
	}
	return _StatusListener;
}
 
Example 12
Project: L2J-Global   File: L2Character.java   View Source Code Vote up 6 votes
/**
 * @return a list of L2Character that attacked.
 */
public final Set<WeakReference<L2Character>> getAttackByList()
{
	if (_attackByList == null)
	{
		synchronized (this)
		{
			if (_attackByList == null)
			{
				_attackByList = ConcurrentHashMap.newKeySet();
			}
		}
	}
	return _attackByList;
}
 
Example 13
Project: L2J-Global   File: MatchingRoomManager.java   View Source Code Vote up 6 votes
public void addToWaitingList(L2PcInstance player)
{
	if (_waitingList == null)
	{
		synchronized (this)
		{
			if (_waitingList == null)
			{
				_waitingList = ConcurrentHashMap.newKeySet(1);
			}
		}
	}
	_waitingList.add(player);
}
 
Example 14
Project: openjdk-jdk10   File: ConcurrentHashMap8Test.java   View Source Code Vote up 6 votes
static Set<Integer> populatedSet(int n) {
    Set<Integer> a = ConcurrentHashMap.<Integer>newKeySet();
    assertTrue(a.isEmpty());
    for (int i = 0; i < n; i++)
        assertTrue(a.add(i));
    assertEquals(n == 0, a.isEmpty());
    assertEquals(n, a.size());
    return a;
}
 
Example 15
Project: quickmon   File: JsonBackedNotifiersRepositoryImpl.java   View Source Code Vote up 5 votes
@Autowired
public JsonBackedNotifiersRepositoryImpl(@Value("${notifiers.file}") File notifierFile, ObjectMapper objectMapper) throws IOException {
    this.notifierSet = ConcurrentHashMap.newKeySet();
    this.notifierFile = notifierFile;
    this.objectMapper = objectMapper;


    if (notifierFile.exists()) {
        loadFromFile();
    } else {
        notifierFile.createNewFile();
        writeToFile();
    }
}
 
Example 16
Project: koryphe   File: SimpleClassNameCache.java   View Source Code Vote up 5 votes
private static Set<Class> createParentClasses() {
    final Set<Class> newParentClasses = ConcurrentHashMap.newKeySet();
    newParentClasses.addAll(DEFAULT_PARENT_CLASSES);
    for (final Class clazz : ReflectionUtil.getAnnotatedTypes(JsonSimpleClassName.class)) {
        final JsonSimpleClassName anno = (JsonSimpleClassName) clazz.getAnnotation(JsonSimpleClassName.class);
        if (null != anno) {
            if (anno.includeSubtypes()) {
                newParentClasses.add(clazz);
            }
        }
    }

    return newParentClasses;
}
 
Example 17
Project: openjdk-jdk10   File: ConcurrentHashMap8Test.java   View Source Code Vote up 5 votes
/**
 * toArray(Integer array) returns an Integer array containing all
 * elements from the set
 */
public void testToArray2() {
    Collection empty = ConcurrentHashMap.newKeySet();
    Integer[] a;
    int size = 20;

    a = new Integer[0];
    assertSame(a, empty.toArray(a));

    a = new Integer[size / 2];
    Arrays.fill(a, 42);
    assertSame(a, empty.toArray(a));
    assertNull(a[0]);
    for (int i = 1; i < a.length; i++)
        assertEquals(42, (int) a[i]);

    Integer[] elements = new Integer[size];
    for (int i = 0; i < size; i++)
        elements[i] = i;
    shuffle(elements);
    Collection<Integer> full = populatedSet(elements);

    Arrays.fill(a, 42);
    assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray(a))));
    for (int i = 0; i < a.length; i++)
        assertEquals(42, (int) a[i]);
    assertSame(Integer[].class, full.toArray(a).getClass());

    a = new Integer[size];
    Arrays.fill(a, 42);
    assertSame(a, full.toArray(a));
    assertTrue(Arrays.asList(elements).containsAll(Arrays.asList(full.toArray(a))));
}
 
Example 18
Project: L2J-Global   File: Quest.java   View Source Code Vote up 5 votes
/**
 * Gets the start conditions.
 * @return the start conditions
 */
private Set<QuestCondition> getStartConditions()
{
	if (_startCondition == null)
	{
		synchronized (this)
		{
			if (_startCondition == null)
			{
				_startCondition = ConcurrentHashMap.newKeySet(1);
			}
		}
	}
	return _startCondition;
}
 
Example 19
Project: ReactPropTypes-Plugin   File: PropTypesHelper.java   View Source Code Vote up 5 votes
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
    Set<Object> seen = ConcurrentHashMap.newKeySet();
    return t -> seen.add(keyExtractor.apply(t));
}
 
Example 20
Project: koryphe   File: ReflectionUtil.java   View Source Code Vote up 5 votes
/**
 * Resets the list of packages that are scanned. It will be set back to the
 * default path and the paths set in the system property
 * "koryphe.reflection.packages".
 */
public static void resetReflectionPackages() {
    packages = ConcurrentHashMap.newKeySet();
    addReflectionPackages(DEFAULT_PACKAGES);
    addReflectionPackages(System.getProperty(PACKAGES_KEY));
}