/* 
 * Copyright (c) 2008-2010, Hazel Ltd. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.hazelcast.monitor;

import com.hazelcast.core.Member;
import com.hazelcast.impl.MemberImpl;
import com.hazelcast.impl.MemberStatsImpl;
import com.hazelcast.nio.DataSerializable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class TimedClusterStats implements DataSerializable {
    long time;
    Map<Member, MemberStatsImpl> memberStats = new HashMap<Member, MemberStatsImpl>();

    public void writeData(DataOutput out) throws IOException {
        out.writeLong(time);
        out.writeInt(memberStats.size());
        Set<Map.Entry<Member, MemberStatsImpl>> memberStatEntries = memberStats.entrySet();
        for (Map.Entry<Member, MemberStatsImpl> memberStatEntry : memberStatEntries) {
            memberStatEntry.getKey().writeData(out);
            memberStatEntry.getValue().writeData(out);
        }
    }

    public void readData(DataInput in) throws IOException {
        time = in.readLong();
        int memberStatsCount = in.readInt();
        for (int i = 0; i < memberStatsCount; i++) {
            Member member = new MemberImpl();
            member.readData(in);
            MemberStatsImpl memberStatsImpl = new MemberStatsImpl();
            memberStatsImpl.readData(in);
            memberStats.put(member, memberStatsImpl);
        }
    }
}


@@ -1,11 +1,10 @@
 /*
- 
 %0A * Copy
@@ -58,17 +58,16 @@
 rved.%0A *
- 
 %0A * Lice
@@ -236,21 +236,19 @@
 cense at
- 
 %0A *
- 
 %0A * http
@@ -288,17 +288,16 @@
 E-2.0%0A *
- 
 %0A * Unle
@@ -1026,16 +1026,99 @@
 e %7B%0A    
+/**%0A%09 *%0A%09 */%0A%09private static final long serialVersionUID = -2924333395156041186L;%0A%09
 long tim
@@ -1139,39 +1139,38 @@
 ber, MemberStats
-Impl
 %3E m
+apM
 emberStats = new
@@ -1197,20 +1197,16 @@
 berStats
-Impl
 %3E();%0A%0A  
@@ -1317,16 +1317,19 @@
 iteInt(m
+apM
 emberSta
@@ -1381,20 +1381,16 @@
 berStats
-Impl
 %3E%3E membe
@@ -1405,16 +1405,19 @@
 ries = m
+apM
 emberSta
@@ -1473,20 +1473,16 @@
 berStats
-Impl
 %3E member
@@ -1929,20 +1929,16 @@
 berStats
-Impl
  memberS
@@ -1941,20 +1941,16 @@
 berStats
-Impl
  = new M
@@ -1990,20 +1990,16 @@
 berStats
-Impl
 .readDat
@@ -2010,32 +2010,35 @@
 );%0A            m
+apM
 emberStats.put(m
@@ -2055,20 +2055,16 @@
 berStats
-Impl
 );%0A     
@@ -2072,13 +2072,329 @@
   %7D%0A    
+%7D%0A%0A%09public long getTime() %7B%0A%09%09return time;%0A%09%7D%0A%0A%09public void setTime(long time) %7B%0A%09%09this.time = time;%0A%09%7D%0A%0A%09public MemberStats putMemberStats(Member member, MemberStats mStats)%7B%0A%09%09return mapMemberStats.put(member, mStats);%0A%09%7D%0A%0A%09public boolean containsKey(Member member) %7B%0A%09%09return mapMemberStats.containsKey(member);%0A%09
 %7D%0A%7D%0A%0A

Use interfaces instead of implementations whenever possible