Search in sources :

Example 1 with AsyncSemaphore

use of org.redisson.pubsub.AsyncSemaphore in project redisson by redisson.

the class MasterSlaveConnectionManager method subscribe.

public RFuture<PubSubConnectionEntry> subscribe(final Codec codec, final String channelName, final RedisPubSubListener<?> listener) {
    final AsyncSemaphore lock = getSemaphore(channelName);
    final RPromise<PubSubConnectionEntry> result = newPromise();
    lock.acquire(new Runnable() {

        @Override
        public void run() {
            RFuture<PubSubConnectionEntry> future = subscribe(codec, channelName, listener, lock);
            future.addListener(new TransferListener<PubSubConnectionEntry>(result));
        }
    });
    return result;
}
Also used : TransferListener(org.redisson.pubsub.TransferListener) AsyncSemaphore(org.redisson.pubsub.AsyncSemaphore) RFuture(org.redisson.api.RFuture)

Example 2 with AsyncSemaphore

use of org.redisson.pubsub.AsyncSemaphore in project redisson by redisson.

the class MasterSlaveConnectionManager method psubscribe.

@Override
public RFuture<PubSubConnectionEntry> psubscribe(final String channelName, final Codec codec, final RedisPubSubListener<?> listener) {
    final AsyncSemaphore lock = getSemaphore(channelName);
    final RPromise<PubSubConnectionEntry> result = newPromise();
    lock.acquire(new Runnable() {

        @Override
        public void run() {
            RFuture<PubSubConnectionEntry> future = psubscribe(channelName, codec, listener, lock);
            future.addListener(new TransferListener<PubSubConnectionEntry>(result));
        }
    });
    return result;
}
Also used : TransferListener(org.redisson.pubsub.TransferListener) AsyncSemaphore(org.redisson.pubsub.AsyncSemaphore) RFuture(org.redisson.api.RFuture)

Example 3 with AsyncSemaphore

use of org.redisson.pubsub.AsyncSemaphore in project redisson by redisson.

the class RedissonTopic method removeAllListeners.

@Override
public void removeAllListeners() {
    AsyncSemaphore semaphore = commandExecutor.getConnectionManager().getSemaphore(name);
    semaphore.acquireUninterruptibly();
    PubSubConnectionEntry entry = commandExecutor.getConnectionManager().getPubSubEntry(name);
    if (entry == null) {
        semaphore.release();
        return;
    }
    entry.removeAllListeners(name);
    if (!entry.hasListeners(name)) {
        commandExecutor.getConnectionManager().unsubscribe(name, semaphore);
    } else {
        semaphore.release();
    }
}
Also used : PubSubConnectionEntry(org.redisson.connection.PubSubConnectionEntry) AsyncSemaphore(org.redisson.pubsub.AsyncSemaphore)

Example 4 with AsyncSemaphore

use of org.redisson.pubsub.AsyncSemaphore in project redisson by redisson.

the class RedissonPatternTopic method removeListener.

@Override
public void removeListener(int listenerId) {
    AsyncSemaphore semaphore = commandExecutor.getConnectionManager().getSemaphore(name);
    semaphore.acquireUninterruptibly();
    PubSubConnectionEntry entry = commandExecutor.getConnectionManager().getPubSubEntry(name);
    if (entry == null) {
        semaphore.release();
        return;
    }
    entry.removeListener(name, listenerId);
    if (!entry.hasListeners(name)) {
        commandExecutor.getConnectionManager().punsubscribe(name, semaphore);
    } else {
        semaphore.release();
    }
}
Also used : PubSubConnectionEntry(org.redisson.connection.PubSubConnectionEntry) AsyncSemaphore(org.redisson.pubsub.AsyncSemaphore)

Example 5 with AsyncSemaphore

use of org.redisson.pubsub.AsyncSemaphore in project redisson by redisson.

the class RedissonPatternTopic method removeAllListeners.

@Override
public void removeAllListeners() {
    AsyncSemaphore semaphore = commandExecutor.getConnectionManager().getSemaphore(name);
    semaphore.acquireUninterruptibly();
    PubSubConnectionEntry entry = commandExecutor.getConnectionManager().getPubSubEntry(name);
    if (entry == null) {
        semaphore.release();
        return;
    }
    entry.removeAllListeners(name);
    if (!entry.hasListeners(name)) {
        commandExecutor.getConnectionManager().punsubscribe(name, semaphore);
    } else {
        semaphore.release();
    }
}
Also used : PubSubConnectionEntry(org.redisson.connection.PubSubConnectionEntry) AsyncSemaphore(org.redisson.pubsub.AsyncSemaphore)

Aggregations

AsyncSemaphore (org.redisson.pubsub.AsyncSemaphore)10 PubSubConnectionEntry (org.redisson.connection.PubSubConnectionEntry)8 RFuture (org.redisson.api.RFuture)2 TransferListener (org.redisson.pubsub.TransferListener)2