/hazelcast/src/main/java/com/hazelcast/jmx/SemaphoreMBean.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 71 lines · 42 code · 11 blank · 18 comment · 0 complexity · e831048692a5ad1a19430f0568590ce2 MD5 · raw file

  1. /*
  2. * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.hazelcast.jmx;
  17. import com.hazelcast.core.ISemaphore;
  18. /**
  19. * MBean for ISemaphore
  20. */
  21. @JMXDescription("A distributed Semaphore")
  22. public class SemaphoreMBean extends AbstractMBean<ISemaphore> {
  23. public SemaphoreMBean(ISemaphore managedObject, ManagementService managementService) {
  24. super(managedObject, managementService);
  25. }
  26. @Override
  27. public ObjectNameSpec getNameSpec() {
  28. return getParentName().getNested("Semaphore", getName());
  29. }
  30. @JMXAttribute("CurrentPermits")
  31. @JMXDescription("availablePermits() result")
  32. public long getCurrentPermits() {
  33. return available();
  34. }
  35. @JMXAttribute("Name")
  36. @JMXDescription("Instance name of the Semaphore")
  37. public String getName() {
  38. return getManagedObject().getName();
  39. }
  40. @JMXOperation("available")
  41. @JMXDescription("number of permits immediately available")
  42. public int available() {
  43. return getManagedObject().availablePermits();
  44. }
  45. @JMXOperation("drain")
  46. @JMXDescription("acquire and return all permits immediately available")
  47. public int drain() {
  48. return getManagedObject().drainPermits();
  49. }
  50. @JMXOperation("reduce")
  51. @JMXDescription("reduce the number of permits available")
  52. public void reduce(int reduction) {
  53. getManagedObject().reducePermits(reduction);
  54. }
  55. @JMXOperation("release")
  56. @JMXDescription("increase the number of permits available")
  57. public void release(int permits) {
  58. getManagedObject().release(permits);
  59. }
  60. }