Example usage for io.netty.util.internal ConcurrentSet ConcurrentSet

List of usage examples for io.netty.util.internal ConcurrentSet ConcurrentSet

Introduction

In this page you can find the example usage for io.netty.util.internal ConcurrentSet ConcurrentSet.

Prototype

public ConcurrentSet() 

Source Link

Document

Creates a new instance which wraps the specified map .

Usage

From source file:com.couchbase.client.core.endpoint.dcp.DCPConnection.java

License:Apache License

public DCPConnection(final CoreEnvironment env, final ClusterFacade core, final String bucket,
        final String password, final SerializedSubject<DCPRequest, DCPRequest> subject) {
    this.env = env;
    this.core = core;
    this.subject = subject;
    this.bucket = bucket;
    this.password = password;
    this.streams = new ConcurrentSet<Short>();
    this.contexts = new ConcurrentHashMap<Short, ChannelHandlerContext>();
}

From source file:com.lambdaworks.redis.pubsub.StatefulRedisPubSubConnectionImpl.java

License:Apache License

/**
 * Initialize a new connection./*from w  w w .j a va  2s .c  o m*/
 *
 * @param writer the channel writer
 * @param codec Codec used to encode/decode keys and values.
 * @param timeout Maximum time to wait for a response.
 * @param unit Unit of time for the timeout.
 */
public StatefulRedisPubSubConnectionImpl(RedisChannelWriter<K, V> writer, RedisCodec<K, V> codec, long timeout,
        TimeUnit unit) {
    super(writer, codec, timeout, unit);

    listeners = new CopyOnWriteArrayList<>();
    channels = new ConcurrentSet<>();
    patterns = new ConcurrentSet<>();
}

From source file:com.netflix.ribbon.examples.rx.RxMovieServer.java

License:Apache License

private Observable<Void> handleUpdateRecommendationsForUser(HttpServerRequest<ByteBuf> request,
        final HttpServerResponse<ByteBuf> response) {
    System.out.println("HTTP request -> update recommendations for user: " + request.getPath());
    final String userId = userIdFromPath(request.getPath());
    if (userId == null) {
        response.setStatus(HttpResponseStatus.BAD_REQUEST);
        return response.close();
    }/* www  . ja v  a2s.c o  m*/
    return request.getContent().flatMap(new Func1<ByteBuf, Observable<Void>>() {
        @Override
        public Observable<Void> call(ByteBuf byteBuf) {
            String movieId = byteBuf.toString(Charset.defaultCharset());
            System.out.println(format("    updating: {user=%s, movie=%s}", userId, movieId));
            synchronized (this) {
                Set<String> recommendations;
                if (userRecommendations.containsKey(userId)) {
                    recommendations = userRecommendations.get(userId);
                } else {
                    recommendations = new ConcurrentSet<String>();
                    userRecommendations.put(userId, recommendations);
                }
                recommendations.add(movieId);
            }
            response.setStatus(HttpResponseStatus.OK);
            return response.close();
        }
    });
}

From source file:com.netflix.ribbon.examples.rx.RxMovieServerTest.java

License:Apache License

@Test
public void testRecommendationsByUserId() throws Exception {
    movieServer.movies.put(ORANGE_IS_THE_NEW_BLACK.getId(), ORANGE_IS_THE_NEW_BLACK);
    movieServer.movies.put(BREAKING_BAD.getId(), BREAKING_BAD);
    Set<String> userRecom = new ConcurrentSet<String>();
    userRecom.add(ORANGE_IS_THE_NEW_BLACK.getId());
    userRecom.add(BREAKING_BAD.getId());
    movieServer.userRecommendations.put(TEST_USER_ID, userRecom);

    Observable<HttpClientResponse<ByteBuf>> httpGet = RxNetty
            .createHttpGet(baseURL + "/users/" + TEST_USER_ID + "/recommendations");
    Movie[] movies = handleGetMoviesReply(httpGet);

    assertTrue(movies[0] != movies[1]);/*from w  ww .  j ava2 s.  com*/
    assertTrue(userRecom.contains(movies[0].getId()));
    assertTrue(userRecom.contains(movies[1].getId()));
}

From source file:com.srotya.linea.topology.TestSpout.java

License:Apache License

@Override
public void configure(Map<String, String> conf, int taskId, Collector collector) {
    this.taskId = taskId;
    this.processed = new AtomicBoolean(false);
    this.collector = collector;
    emittedEvents = new ConcurrentSet<>();
}

From source file:de.ellpeck.actuallyadditions.mod.misc.apiimpl.LaserRelayConnectionHandler.java

/**
 * Gets all Connections for a Relay//  w  ww  .  ja  v  a  2 s  . c  om
 */
@Override
public ConcurrentSet<IConnectionPair> getConnectionsFor(BlockPos relay, World world) {
    ConcurrentSet<IConnectionPair> allPairs = new ConcurrentSet<IConnectionPair>();
    for (Network aNetwork : WorldData.getDataForWorld(world).laserRelayNetworks) {
        for (IConnectionPair pair : aNetwork.connections) {
            if (pair.contains(relay)) {
                allPairs.add(pair);
            }
        }
    }
    return allPairs;
}

From source file:io.lettuce.core.masterslave.MasterSlaveConnectionProvider.java

License:Apache License

/**
 * @return all connections that are connected.
 *///from  ww  w  . j  av  a 2s.  c o m
@Deprecated
protected Collection<StatefulRedisConnection<K, V>> allConnections() {

    Set<StatefulRedisConnection<K, V>> set = new ConcurrentSet<>();
    connectionProvider.forEach(set::add);
    return set;
}

From source file:io.lettuce.core.pubsub.PubSubEndpoint.java

License:Apache License

/**
 * Initialize a new instance that handles commands from the supplied queue.
 *
 * @param clientOptions client options for this connection, must not be {@literal null}
 * @param clientResources client resources for this connection, must not be {@literal null}.
 *//* w w w .  j a v a 2 s.c o m*/
public PubSubEndpoint(ClientOptions clientOptions, ClientResources clientResources) {

    super(clientOptions, clientResources);

    this.channels = new ConcurrentSet<>();
    this.patterns = new ConcurrentSet<>();
}

From source file:io.pravega.controller.server.retention.StreamCutService.java

License:Open Source License

public StreamCutService(final int bucketCount, String processId, final StreamMetadataStore streamMetadataStore,
        final StreamMetadataTasks streamMetadataTasks, final ScheduledExecutorService executor) {
    this.bucketCount = bucketCount;
    this.processId = processId;
    this.streamMetadataStore = streamMetadataStore;
    this.streamMetadataTasks = streamMetadataTasks;
    this.executor = executor;
    this.buckets = new ConcurrentSet<>();
}

From source file:org.apache.reef.tests.applications.vortex.addone.AddOneCallbackTestStart.java

License:Apache License

/**
 * Test correctness of a simple vector calculation on Vortex, checking results with callbacks.
 *///from   www. j a  v  a 2 s  .c o m
@Override
public void start(final VortexThreadPool vortexThreadPool) {
    final Vector<Integer> inputVector = new Vector<>();
    final int expectedCallbacks = 1000;
    final CountDownLatch latch = new CountDownLatch(expectedCallbacks);
    final ConcurrentSet<Integer> outputSet = new ConcurrentSet<>();
    for (int i = 0; i < expectedCallbacks; i++) {
        inputVector.add(i);
    }

    final List<VortexFuture<Integer>> futures = new ArrayList<>();
    final AddOneFunction addOneFunction = new AddOneFunction();

    for (final int i : inputVector) {
        futures.add(vortexThreadPool.submit(addOneFunction, i, new EventHandler<Integer>() {
            @Override
            public void onNext(final Integer value) {
                outputSet.add(value - 1);
                latch.countDown();
            }
        }));
    }

    try {
        latch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
        Assert.fail();
    }

    Assert.assertTrue(outputSet.containsAll(inputVector));
    Assert.assertTrue(inputVector.containsAll(outputSet));
}