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

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 169 lines · 131 code · 23 blank · 15 comment · 15 complexity · b5127fe2b389b73c4849e686dbf31ee6 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.impl.monitor.MemberStateImpl;
  18. import com.hazelcast.nio.DataSerializable;
  19. import java.io.DataInput;
  20. import java.io.DataOutput;
  21. import java.io.IOException;
  22. import java.util.ArrayList;
  23. import java.util.HashSet;
  24. import java.util.List;
  25. import java.util.Set;
  26. public class TimedMemberState implements DataSerializable, Cloneable {
  27. long time;
  28. MemberState memberState = null;
  29. Set<String> instanceNames = null;
  30. List<String> memberList;
  31. List<String> executorList;
  32. Boolean master;
  33. String clusterName;
  34. public TimedMemberState clone() {
  35. TimedMemberState st = new TimedMemberState();
  36. st.setTime(time);
  37. st.setMemberState(memberState);
  38. st.setInstanceNames(instanceNames);
  39. st.setMemberList(memberList);
  40. st.setMaster(master);
  41. st.setClusterName(clusterName);
  42. return st;
  43. }
  44. public void writeData(DataOutput out) throws IOException {
  45. out.writeLong(time);
  46. out.writeBoolean(master);
  47. memberState.writeData(out);
  48. out.writeUTF(clusterName);
  49. int nameCount = (instanceNames == null) ? 0 : instanceNames.size();
  50. out.writeInt(nameCount);
  51. if (instanceNames != null) {
  52. for (String name : instanceNames) {
  53. out.writeUTF(name);
  54. }
  55. }
  56. int memberCount = (memberList == null) ? 0 : memberList.size();
  57. out.writeInt(memberCount);
  58. if (memberList != null) {
  59. for (String address : memberList) {
  60. out.writeUTF(address);
  61. }
  62. }
  63. int execCount = (executorList == null) ? 0 : executorList.size();
  64. out.writeInt(execCount);
  65. if (executorList != null) {
  66. for (String exec : executorList) {
  67. out.writeUTF(exec);
  68. }
  69. }
  70. }
  71. public void readData(DataInput in) throws IOException {
  72. time = in.readLong();
  73. master = in.readBoolean();
  74. memberState = new MemberStateImpl();
  75. memberState.readData(in);
  76. clusterName = in.readUTF();
  77. int nameCount = in.readInt();
  78. instanceNames = new HashSet<String>(nameCount);
  79. for (int i = 0; i < nameCount; i++) {
  80. instanceNames.add(in.readUTF());
  81. }
  82. int memberCount = in.readInt();
  83. memberList = new ArrayList<String>();
  84. for (int i = 0; i < memberCount; i++) {
  85. memberList.add(in.readUTF());
  86. }
  87. int execCount = in.readInt();
  88. executorList = new ArrayList<String>();
  89. for (int i = 0; i < execCount; i++) {
  90. executorList.add(in.readUTF());
  91. }
  92. }
  93. public List<String> getMemberList() {
  94. return memberList;
  95. }
  96. public void setMemberList(List<String> memberList) {
  97. this.memberList = memberList;
  98. }
  99. public Boolean getMaster() {
  100. return master;
  101. }
  102. public void setMaster(Boolean master) {
  103. this.master = master;
  104. }
  105. public String getClusterName() {
  106. return clusterName;
  107. }
  108. public void setClusterName(String clusterName) {
  109. this.clusterName = clusterName;
  110. }
  111. public void setTime(long time) {
  112. this.time = time;
  113. }
  114. public long getTime() {
  115. return time;
  116. }
  117. public Set<String> getInstanceNames() {
  118. return instanceNames;
  119. }
  120. public void setInstanceNames(Set<String> longInstanceNames) {
  121. this.instanceNames = longInstanceNames;
  122. }
  123. @Override
  124. public String toString() {
  125. StringBuilder sb = new StringBuilder("TimedMemberState{\n");
  126. sb.append("\t");
  127. sb.append(memberState);
  128. sb.append("\n");
  129. sb.append("}\n");
  130. sb.append("Instances : ");
  131. sb.append(instanceNames);
  132. return sb.toString();
  133. }
  134. public MemberState getMemberState() {
  135. return memberState;
  136. }
  137. public void setMemberState(MemberState memberState) {
  138. this.memberState = memberState;
  139. }
  140. public List<String> getExecutorList() {
  141. return executorList;
  142. }
  143. public void setExecutorList(List<String> executorList) {
  144. this.executorList = executorList;
  145. }
  146. }