PageRenderTime 54ms CodeModel.GetById 17ms app.highlight 31ms RepoModel.GetById 2ms app.codeStats 0ms

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