PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/monitor/DistributedMemberInfoCallable.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 92 lines | 63 code | 14 blank | 15 comment | 2 complexity | 33e03129048a330ab283335a29d10fa8 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.monitor;
18
19import com.hazelcast.core.HazelcastInstance;
20import com.hazelcast.core.HazelcastInstanceAware;
21import com.hazelcast.util.Clock;
22import com.hazelcast.partition.Partition;
23
24import java.io.Serializable;
25import java.util.HashSet;
26import java.util.Properties;
27import java.util.Set;
28import java.util.concurrent.Callable;
29
30public class DistributedMemberInfoCallable implements Callable<DistributedMemberInfoCallable.MemberInfo>, Serializable, HazelcastInstanceAware {
31    private transient HazelcastInstance hazelcastInstance;
32
33    public MemberInfo call() throws Exception {
34        MemberInfo memberInfo = new MemberInfo();
35        Set<Integer> partitions = new HashSet<Integer>();
36        for (Partition partition : hazelcastInstance.getPartitionService().getPartitions()) {
37            if (hazelcastInstance.getCluster().getLocalMember().equals(partition.getOwner())) {
38                partitions.add(partition.getPartitionId());
39            }
40        }
41        memberInfo.partitions = partitions;
42        memberInfo.time = Clock.currentTimeMillis();
43        memberInfo.totalMemory = Runtime.getRuntime().totalMemory();
44        memberInfo.freeMemory = Runtime.getRuntime().freeMemory();
45        memberInfo.maxMemory = Runtime.getRuntime().maxMemory();
46        memberInfo.availableProcessors = Runtime.getRuntime().availableProcessors();
47        memberInfo.systemProps = System.getProperties();
48        return memberInfo;
49    }
50
51    public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
52        this.hazelcastInstance = hazelcastInstance;
53    }
54
55    public static class MemberInfo implements Serializable {
56        private Set<Integer> partitions;
57        private long time;
58        private long totalMemory;
59        private long freeMemory;
60        public long maxMemory;
61        public int availableProcessors;
62        public Properties systemProps;
63
64        public Set<Integer> getPartitions() {
65            return partitions;
66        }
67
68        public long getTime() {
69            return time;
70        }
71
72        public long getTotalMemory() {
73            return totalMemory;
74        }
75
76        public long getFreeMemory() {
77            return freeMemory;
78        }
79
80        public long getMaxMemory() {
81            return maxMemory;
82        }
83
84        public int getAvailableProcessors() {
85            return availableProcessors;
86        }
87
88        public Properties getSystemProps() {
89            return systemProps;
90        }
91    }
92}