Tabnine Logo
RedissonClient.getSemaphore
Code IndexAdd Tabnine to your IDE (free)

How to use
getSemaphore
method
in
org.redisson.api.RedissonClient

Best Java code snippets using org.redisson.api.RedissonClient.getSemaphore (Showing top 12 results out of 315)

origin: redisson/redisson

semaphore = redisson.getSemaphore(suffixName(getName(), "semaphore"));
listenerId = topic.addListener(Long.class, new MessageListener<Long>() {
origin: redisson/redisson

semaphore = redisson.getSemaphore(suffixName(getName(), "semaphore"));
listenerId = topic.addListener(Long.class, new MessageListener<Long>() {
origin: io.lsn/spring-core

  /**
   * get named semaphore
   *
   * @param name
   * @return
   */
  public RSemaphore getSemaphore(String name) {
    RSemaphore semaphore = redissonClient.getSemaphore(name);
    semaphore.trySetPermits(1);
    return semaphore;
  }
}
origin: io.lsn.spring/utilities

  /**
   * get named semaphore
   *
   * @param name
   * @return
   */
  public RSemaphore getSemaphore(String name) {
    RSemaphore semaphore = redissonClient.getSemaphore(name);
    semaphore.trySetPermits(1);
    return semaphore;
  }
}
origin: jjj124/SpringLimiter

@Override
public void release(Object key, int permits) {
  RSemaphore rSemaphore = redisson.getSemaphore(key.toString());
  rSemaphore.release();
}
origin: jjj124/SpringLimiter

@Override
public boolean acquire(Object key, int permits) {
  RSemaphore rSemaphore = redisson.getSemaphore(key.toString());
  rSemaphore.trySetPermits(permits);
  return rSemaphore.tryAcquire();
}
origin: justlive1/earth-frost

private void waitFor(String uuid, int subscribers) {
 RSemaphore semaphore = redissonClient.getSemaphore(String.format(JobConfig.WORKER_REQ, uuid));
 try {
  semaphore.tryAcquire(subscribers, 10L, TimeUnit.SECONDS);
 } catch (InterruptedException e) {
  Thread.currentThread().interrupt();
 }
 redissonClient.getKeys().delete(semaphore);
}
origin: redisson/redisson-examples

  @Override
  public void run() {
    RSemaphore s = redisson.getSemaphore("test");
    s.release();
    s.release();
  }
};
origin: org.hswebframework/hsweb-task-cluster

@Override
@SneakyThrows
public Lock tryGetLock(String lockName, long timeout, TimeUnit timeUnit) {
  String id = IdUtils.newUUID();
  RSemaphore semaphore = rSemaphoreMap.computeIfAbsent(lockName, key -> {
    RSemaphore rSemaphore = redissonClient.getSemaphore(key);
    rSemaphore.trySetPermits(1);
    return rSemaphore;
  });
  log.debug("try lock {} permits:{},id={}", lockName, semaphore.availablePermits(), id);
  boolean success = semaphore.tryAcquire(timeout, timeUnit);
  if (!success) {
    throw new TimeoutException("try lock " + lockName + " timeout");
  }
  return () -> {
    semaphore.release();
    log.debug("unlock {},id={}", lockName, id);
  };
}
origin: redisson/redisson-examples

public static void main(String[] args) throws InterruptedException {
  // connects to 127.0.0.1:6379 by default
  RedissonClient redisson = Redisson.create();
  RSemaphore s = redisson.getSemaphore("test");
  s.trySetPermits(5);
  s.acquire(3);
  Thread t = new Thread() {
    @Override
    public void run() {
      RSemaphore s = redisson.getSemaphore("test");
      s.release();
      s.release();
    }
  };
  t.start();
  s.acquire(4);
  
  redisson.shutdown();
}

origin: justlive1/earth-frost

@Override
public void register() {
 List<JobGroup> jobGroups = jobExecutor.getGroups();
 if (jobGroups == null || jobGroups.isEmpty()) {
  log.info("no jobs need to register");
  return;
 }
 // 注册job执行器
 for (JobGroup jobGroup : jobGroups) {
  String key = String
    .format(JobConfig.JOB_BEAN_CHANNEL, jobGroup.getGroupKey(), jobGroup.getJobKey());
  log.info("register job [{}]", key);
  redissonClient.getExecutorService(key).registerWorkers(JobConfig.getParallel());
 }
 // script执行器
 if (JobConfig.getExecutor().getScriptJobEnabled()) {
  redissonClient.getExecutorService(String.format(JobConfig.JOB_SCRIPT_CHANNEL, ""))
    .registerWorkers(JobConfig.getParallel());
  redissonClient
    .getExecutorService(String.format(JobConfig.JOB_SCRIPT_CHANNEL, jobExecutor.getKey()))
    .registerWorkers(JobConfig.getParallel());
 }
 // 订阅worker
 redissonClient.<String>getTopic(JobConfig.WORKER_REGISTER).addListener((channel, uuid) -> {
  redissonClient.getMapCache(String.format(JobConfig.WORKER_REQ_VAL, uuid))
    .put(jobExecutor.getId(), jobExecutor, 20, TimeUnit.SECONDS);
  redissonClient.getSemaphore(String.format(JobConfig.WORKER_REQ, uuid)).release();
 });
}
origin: org.redisson/redisson

semaphore = redisson.getSemaphore(suffixName(getName(), "semaphore"));
listenerId = topic.addListener(Long.class, new MessageListener<Long>() {
org.redisson.apiRedissonClientgetSemaphore

Javadoc

Returns semaphore instance by name

Popular methods of RedissonClient

  • shutdown
    Shuts down Redisson instance but NOT Redis server Shutdown ensures that no tasks are submitted for '
  • getMap
    Returns map instance by name using provided codec for both map keys and values.
  • getLock
    Returns lock instance by name. Implements a non-fair locking so doesn't guarantees an acquire order
  • getTopic
    Returns topic instance by name using provided codec for messages.
  • getBucket
    Returns object holder instance by name using provided codec for object.
  • getConfig
    Allows to get configuration provided during Redisson instance creation. Further changes on this obje
  • getMapCache
    Returns map-based cache instance by name using provided codec for both cache keys and values. Suppor
  • getAtomicLong
    Returns atomicLong instance by name.
  • getKeys
    Returns interface with methods for Redis keys. Each of Redis/Redisson object associated with own key
  • getScript
    Returns script operations object using provided codec.
  • getSet
    Returns set instance by name using provided codec for set objects.
  • getBlockingQueue
    Returns unbounded blocking queue instance by name using provided codec for queue objects.
  • getSet,
  • getBlockingQueue,
  • getList,
  • getScoredSortedSet,
  • getExecutorService,
  • getFairLock,
  • getQueue,
  • getReadWriteLock,
  • getListMultimap

Popular in Java

  • Updating database using SQL prepared statement
  • getResourceAsStream (ClassLoader)
  • setRequestProperty (URLConnection)
  • addToBackStack (FragmentTransaction)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now