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