PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
17package com.hazelcast.jmx;
18
19import com.hazelcast.core.ISemaphore;
20
21/**
22 * MBean for ISemaphore
23 */
24@JMXDescription("A distributed Semaphore")
25public class SemaphoreMBean extends AbstractMBean<ISemaphore> {
26
27    public SemaphoreMBean(ISemaphore managedObject, ManagementService managementService) {
28        super(managedObject, managementService);
29    }
30
31    @Override
32    public ObjectNameSpec getNameSpec() {
33        return getParentName().getNested("Semaphore", getName());
34    }
35
36    @JMXAttribute("CurrentPermits")
37    @JMXDescription("availablePermits() result")
38    public long getCurrentPermits() {
39        return available();
40    }
41
42    @JMXAttribute("Name")
43    @JMXDescription("Instance name of the Semaphore")
44    public String getName() {
45        return getManagedObject().getName();
46    }
47
48    @JMXOperation("available")
49    @JMXDescription("number of permits immediately available")
50    public int available() {
51        return getManagedObject().availablePermits();
52    }
53
54    @JMXOperation("drain")
55    @JMXDescription("acquire and return all permits immediately available")
56    public int drain() {
57        return getManagedObject().drainPermits();
58    }
59
60    @JMXOperation("reduce")
61    @JMXDescription("reduce the number of permits available")
62    public void reduce(int reduction) {
63        getManagedObject().reducePermits(reduction);
64    }
65
66    @JMXOperation("release")
67    @JMXDescription("increase the number of permits available")
68    public void release(int permits) {
69        getManagedObject().release(permits);
70    }
71}