View | Details | Raw Unified | Return to bug 54330
Collapse All | Expand All

(-)java/org/apache/catalina/tribes/Member.java (+28 lines)
Lines 27-32 Link Here
27
 * since a member that has crashed and the starts up again on the same port/host is
27
 * since a member that has crashed and the starts up again on the same port/host is
28
 * not guaranteed to be the same member, so no state transfers will ever be confused
28
 * not guaranteed to be the same member, so no state transfers will ever be confused
29
 * @author Filip Hanik
29
 * @author Filip Hanik
30
 * @author Greg Turnquist
30
 * @version $Id$
31
 * @version $Id$
31
 */
32
 */
32
33
Lines 81-86 Link Here
81
     */
82
     */
82
    public long getMemberAliveTime();
83
    public long getMemberAliveTime();
83
84
85
    public void setMemberAliveTime(long memberAliveTime);
86
84
    /**
87
    /**
85
     * The current state of the member
88
     * The current state of the member
86
     * @return boolean - true if the member is functioning correctly
89
     * @return boolean - true if the member is functioning correctly
Lines 111-125 Link Here
111
     */
114
     */
112
    public byte[] getPayload();
115
    public byte[] getPayload();
113
116
117
    public void setPayload(byte[] payload);
118
114
    /**
119
    /**
115
     * returns the command associated with this member
120
     * returns the command associated with this member
116
     * @return byte[]
121
     * @return byte[]
117
     */
122
     */
118
    public byte[] getCommand();
123
    public byte[] getCommand();
119
124
125
    public void setCommand(byte[] command);
126
120
    /**
127
    /**
121
     * Domain for this cluster
128
     * Domain for this cluster
122
     * @return byte[]
129
     * @return byte[]
123
     */
130
     */
124
    public byte[] getDomain();
131
    public byte[] getDomain();
132
133
    /**
134
     * 
135
     * @param getalive boolean - calculate memberAlive time
136
     * @param reset boolean - reset the cached data package, and create a new one
137
     * @return byte[]
138
     */
139
    public byte[] getData(boolean getalive, boolean reset);
140
141
    /**
142
     * 
143
     * @param getalive boolean - calculate memberAlive time
144
     * @return byte[]
145
     */
146
    public byte[] getData(boolean getalive);
147
148
    /**
149
     * Retrieve the total size of the message.
150
     * @return int - number of bytes in the message
151
     */
152
    public int getDataLength();
125
}
153
}
(-)java/org/apache/catalina/tribes/group/interceptors/DomainFilterInterceptor.java (-4 / +4 lines)
Lines 21-27 Link Here
21
import org.apache.catalina.tribes.ChannelMessage;
21
import org.apache.catalina.tribes.ChannelMessage;
22
import org.apache.catalina.tribes.Member;
22
import org.apache.catalina.tribes.Member;
23
import org.apache.catalina.tribes.group.ChannelInterceptorBase;
23
import org.apache.catalina.tribes.group.ChannelInterceptorBase;
24
import org.apache.catalina.tribes.membership.MemberImpl;
25
import org.apache.catalina.tribes.membership.Membership;
24
import org.apache.catalina.tribes.membership.Membership;
26
25
27
/**
26
/**
Lines 31-36 Link Here
31
 * </p>
30
 * </p>
32
 *
31
 *
33
 * @author Filip Hanik
32
 * @author Filip Hanik
33
 * @author Greg Turnquist
34
 * @version 1.0
34
 * @version 1.0
35
 */
35
 */
36
public class DomainFilterInterceptor extends ChannelInterceptorBase {
36
public class DomainFilterInterceptor extends ChannelInterceptorBase {
Lines 52-58 Link Here
52
        boolean notify = false;
52
        boolean notify = false;
53
        synchronized (membership) {
53
        synchronized (membership) {
54
            notify = Arrays.equals(domain,member.getDomain());
54
            notify = Arrays.equals(domain,member.getDomain());
55
            if ( notify ) notify = membership.memberAlive((MemberImpl)member);
55
            if ( notify ) notify = membership.memberAlive(member);
56
        }
56
        }
57
        if ( notify ) super.memberAdded(member);
57
        if ( notify ) super.memberAdded(member);
58
    }
58
    }
Lines 63-69 Link Here
63
        boolean notify = false;
63
        boolean notify = false;
64
        synchronized (membership) {
64
        synchronized (membership) {
65
            notify = Arrays.equals(domain,member.getDomain());
65
            notify = Arrays.equals(domain,member.getDomain());
66
            membership.removeMember((MemberImpl)member);
66
            membership.removeMember(member);
67
        }
67
        }
68
        if ( notify ) super.memberDisappeared(member);
68
        if ( notify ) super.memberDisappeared(member);
69
    }
69
    }
Lines 94-100 Link Here
94
94
95
    protected synchronized void setupMembership() {
95
    protected synchronized void setupMembership() {
96
        if ( membership == null ) {
96
        if ( membership == null ) {
97
            membership = new Membership((MemberImpl)super.getLocalMember(true));
97
            membership = new Membership(super.getLocalMember(true));
98
        }
98
        }
99
99
100
    }
100
    }
(-)java/org/apache/catalina/tribes/group/interceptors/NonBlockingCoordinator.java (-32 / +30 lines)
Lines 116-125 Link Here
116
 * <a href="http://people.apache.org/~fhanik/tribes/docs/leader-election-message-arrives.jpg">Receive an election message</a><br><br>
116
 * <a href="http://people.apache.org/~fhanik/tribes/docs/leader-election-message-arrives.jpg">Receive an election message</a><br><br>
117
 *
117
 *
118
 * @author Filip Hanik
118
 * @author Filip Hanik
119
 * @author Greg Turnquist
119
 * @version 1.0
120
 * @version 1.0
120
 *
121
 *
122
 *
123
 */
121
 */
124
public class NonBlockingCoordinator extends ChannelInterceptorBase {
122
public class NonBlockingCoordinator extends ChannelInterceptorBase {
125
123
Lines 187-194 Link Here
187
185
188
    public void startElection(boolean force) throws ChannelException {
186
    public void startElection(boolean force) throws ChannelException {
189
        synchronized (electionMutex) {
187
        synchronized (electionMutex) {
190
            MemberImpl local = (MemberImpl)getLocalMember(false);
188
            Member local = getLocalMember(false);
191
            MemberImpl[] others = membership.getMembers();
189
            Member[] others = membership.getMembers();
192
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START_ELECT,this,"Election initated"));
190
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START_ELECT,this,"Election initated"));
193
            if ( others.length == 0 ) {
191
            if ( others.length == 0 ) {
194
                this.viewId = new UniqueId(UUIDGenerator.randomUUID(false));
192
                this.viewId = new UniqueId(UUIDGenerator.randomUUID(false));
Lines 212-218 Link Here
212
                return; //already have this view installed
210
                return; //already have this view installed
213
            }
211
            }
214
            int prio = AbsoluteOrder.comp.compare(local,others[0]);
212
            int prio = AbsoluteOrder.comp.compare(local,others[0]);
215
            MemberImpl leader = ( prio < 0 )?local:others[0];//am I the leader in my view?
213
            Member leader = ( prio < 0 )?local:others[0];//am I the leader in my view?
216
            if ( local.equals(leader) || force ) {
214
            if ( local.equals(leader) || force ) {
217
                CoordinationMessage msg = createElectionMsg(local, others, leader);
215
                CoordinationMessage msg = createElectionMsg(local, others, leader);
218
                suggestedviewId = msg.getId();
216
                suggestedviewId = msg.getId();
Lines 244-264 Link Here
244
        }
242
        }
245
    }
243
    }
246
244
247
    private CoordinationMessage createElectionMsg(MemberImpl local, MemberImpl[] others, MemberImpl leader) {
245
    private CoordinationMessage createElectionMsg(Member local, Member[] others, Member leader) {
248
        Membership m = new Membership(local,AbsoluteOrder.comp,true);
246
        Membership m = new Membership(local,AbsoluteOrder.comp,true);
249
        Arrays.fill(m,others);
247
        Arrays.fill(m,others);
250
        MemberImpl[] mbrs = m.getMembers();
248
        Member[] mbrs = m.getMembers();
251
        m.reset();
249
        m.reset();
252
        CoordinationMessage msg = new CoordinationMessage(leader, local, mbrs,new UniqueId(UUIDGenerator.randomUUID(true)), COORD_REQUEST);
250
        CoordinationMessage msg = new CoordinationMessage(leader, local, mbrs,new UniqueId(UUIDGenerator.randomUUID(true)), COORD_REQUEST);
253
        return msg;
251
        return msg;
254
    }
252
    }
255
253
256
    protected void sendElectionMsg(MemberImpl local, MemberImpl next, CoordinationMessage msg) throws ChannelException {
254
    protected void sendElectionMsg(Member local, Member next, CoordinationMessage msg) throws ChannelException {
257
        fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_SEND_MSG,this,"Sending election message to("+next.getName()+")"));
255
        fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_SEND_MSG,this,"Sending election message to("+next.getName()+")"));
258
        super.sendMessage(new Member[] {next}, createData(msg, local), null);
256
        super.sendMessage(new Member[] {next}, createData(msg, local), null);
259
    }
257
    }
260
258
261
    protected void sendElectionMsgToNextInline(MemberImpl local, CoordinationMessage msg) throws ChannelException {
259
    protected void sendElectionMsgToNextInline(Member local, CoordinationMessage msg) throws ChannelException {
262
        int next = Arrays.nextIndex(local,msg.getMembers());
260
        int next = Arrays.nextIndex(local,msg.getMembers());
263
        int current = next;
261
        int current = next;
264
        msg.leader = msg.getMembers()[0];
262
        msg.leader = msg.getMembers()[0];
Lines 275-281 Link Here
275
        }
273
        }
276
    }
274
    }
277
275
278
    public ChannelData createData(CoordinationMessage msg, MemberImpl local) {
276
    public ChannelData createData(CoordinationMessage msg, Member local) {
279
        msg.write();
277
        msg.write();
280
        ChannelData data = new ChannelData(true);
278
        ChannelData data = new ChannelData(true);
281
        data.setAddress(local);
279
        data.setAddress(local);
Lines 297-309 Link Here
297
295
298
    protected Membership mergeOnArrive(CoordinationMessage msg) {
296
    protected Membership mergeOnArrive(CoordinationMessage msg) {
299
        fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_PRE_MERGE,this,"Pre merge"));
297
        fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_PRE_MERGE,this,"Pre merge"));
300
        MemberImpl local = (MemberImpl)getLocalMember(false);
298
        Member local = getLocalMember(false);
301
        Membership merged = new Membership(local,AbsoluteOrder.comp,true);
299
        Membership merged = new Membership(local,AbsoluteOrder.comp,true);
302
        Arrays.fill(merged,msg.getMembers());
300
        Arrays.fill(merged,msg.getMembers());
303
        Arrays.fill(merged,getMembers());
301
        Arrays.fill(merged,getMembers());
304
        Member[] diff = Arrays.diff(merged,membership,local);
302
        Member[] diff = Arrays.diff(merged,membership,local);
305
        for ( int i=0; i<diff.length; i++ ) {
303
        for ( int i=0; i<diff.length; i++ ) {
306
            if (!alive(diff[i])) merged.removeMember((MemberImpl)diff[i]);
304
            if (!alive(diff[i])) merged.removeMember(diff[i]);
307
            else memberAdded(diff[i],false);
305
            else memberAdded(diff[i],false);
308
        }
306
        }
309
        fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_POST_MERGE,this,"Post merge"));
307
        fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_POST_MERGE,this,"Post merge"));
Lines 321-327 Link Here
321
    }
319
    }
322
320
323
    protected void handleToken(CoordinationMessage msg, Membership merged) throws ChannelException {
321
    protected void handleToken(CoordinationMessage msg, Membership merged) throws ChannelException {
324
        MemberImpl local = (MemberImpl)getLocalMember(false);
322
        Member local = getLocalMember(false);
325
        if ( local.equals(msg.getSource()) ) {
323
        if ( local.equals(msg.getSource()) ) {
326
            //my message msg.src=local
324
            //my message msg.src=local
327
            handleMyToken(local, msg, merged);
325
            handleMyToken(local, msg, merged);
Lines 330-336 Link Here
330
        }
328
        }
331
    }
329
    }
332
330
333
    protected void handleMyToken(MemberImpl local, CoordinationMessage msg, Membership merged) throws ChannelException {
331
    protected void handleMyToken(Member local, CoordinationMessage msg, Membership merged) throws ChannelException {
334
        if ( local.equals(msg.getLeader()) ) {
332
        if ( local.equals(msg.getLeader()) ) {
335
            //no leadership change
333
            //no leadership change
336
            if ( Arrays.sameMembers(msg.getMembers(),merged.getMembers()) ) {
334
            if ( Arrays.sameMembers(msg.getMembers(),merged.getMembers()) ) {
Lines 354-360 Link Here
354
        }
352
        }
355
    }
353
    }
356
354
357
    protected void handleOtherToken(MemberImpl local, CoordinationMessage msg, Membership merged) throws ChannelException {
355
    protected void handleOtherToken(Member local, CoordinationMessage msg, Membership merged) throws ChannelException {
358
        if ( local.equals(msg.getLeader()) ) {
356
        if ( local.equals(msg.getLeader()) ) {
359
            //I am the new leader
357
            //I am the new leader
360
            //startElection(false);
358
            //startElection(false);
Lines 366-372 Link Here
366
364
367
    protected void handleViewConf(CoordinationMessage msg, Membership merged) throws ChannelException {
365
    protected void handleViewConf(CoordinationMessage msg, Membership merged) throws ChannelException {
368
        if ( viewId != null && msg.getId().equals(viewId) ) return;//we already have this view
366
        if ( viewId != null && msg.getId().equals(viewId) ) return;//we already have this view
369
        view = new Membership((MemberImpl)getLocalMember(false),AbsoluteOrder.comp,true);
367
        view = new Membership(getLocalMember(false),AbsoluteOrder.comp,true);
370
        Arrays.fill(view,msg.getMembers());
368
        Arrays.fill(view,msg.getMembers());
371
        viewId = msg.getId();
369
        viewId = msg.getId();
372
370
Lines 449-455 Link Here
449
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START, this, "Before start"));
447
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START, this, "Before start"));
450
            super.start(startsvc);
448
            super.start(startsvc);
451
            started = true;
449
            started = true;
452
            if (view == null) view = new Membership( (MemberImpl)super.getLocalMember(true), AbsoluteOrder.comp, true);
450
            if (view == null) view = new Membership(super.getLocalMember(true), AbsoluteOrder.comp, true);
453
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START, this, "After start"));
451
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START, this, "After start"));
454
            startElection(false);
452
            startElection(false);
455
    }
453
    }
Lines 510-516 Link Here
510
    public void memberAdded(Member member,boolean elect) {
508
    public void memberAdded(Member member,boolean elect) {
511
        try {
509
        try {
512
            if ( membership == null ) setupMembership();
510
            if ( membership == null ) setupMembership();
513
            if ( membership.memberAlive((MemberImpl)member) ) super.memberAdded(member);
511
            if ( membership.memberAlive(member)) super.memberAdded(member);
514
            try {
512
            try {
515
                fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MBR_ADD,this,"Member add("+member.getName()+")"));
513
                fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MBR_ADD,this,"Member add("+member.getName()+")"));
516
                if (started && elect) startElection(false);
514
                if (started && elect) startElection(false);
Lines 526-532 Link Here
526
    public void memberDisappeared(Member member) {
524
    public void memberDisappeared(Member member) {
527
        try {
525
        try {
528
526
529
            membership.removeMember((MemberImpl)member);
527
            membership.removeMember(member);
530
            super.memberDisappeared(member);
528
            super.memberDisappeared(member);
531
            try {
529
            try {
532
                fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MBR_DEL,this,"Member remove("+member.getName()+")"));
530
                fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MBR_DEL,this,"Member remove("+member.getName()+")"));
Lines 553-559 Link Here
553
    @Override
551
    @Override
554
    public void heartbeat() {
552
    public void heartbeat() {
555
        try {
553
        try {
556
            MemberImpl local = (MemberImpl)getLocalMember(false);
554
            Member local = getLocalMember(false);
557
            if ( view != null && (Arrays.diff(view,membership,local).length != 0 ||  Arrays.diff(membership,view,local).length != 0) ) {
555
            if ( view != null && (Arrays.diff(view,membership,local).length != 0 ||  Arrays.diff(membership,view,local).length != 0) ) {
558
                if ( isHighest() ) {
556
                if ( isHighest() ) {
559
                    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START_ELECT, this,
557
                    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_START_ELECT, this,
Lines 612-618 Link Here
612
610
613
    protected synchronized void setupMembership() {
611
    protected synchronized void setupMembership() {
614
        if ( membership == null ) {
612
        if ( membership == null ) {
615
            membership  = new Membership((MemberImpl)super.getLocalMember(true),AbsoluteOrder.comp,false);
613
            membership  = new Membership(super.getLocalMember(true),AbsoluteOrder.comp,false);
616
        }
614
        }
617
    }
615
    }
618
616
Lines 625-633 Link Here
625
    public static class CoordinationMessage {
623
    public static class CoordinationMessage {
626
        //X{A-ldr, A-src, mbrs-A,B,C,D}
624
        //X{A-ldr, A-src, mbrs-A,B,C,D}
627
        protected final XByteBuffer buf;
625
        protected final XByteBuffer buf;
628
        protected MemberImpl leader;
626
        protected Member leader;
629
        protected MemberImpl source;
627
        protected Member source;
630
        protected MemberImpl[] view;
628
        protected Member[] view;
631
        protected UniqueId id;
629
        protected UniqueId id;
632
        protected byte[] type;
630
        protected byte[] type;
633
631
Lines 636-644 Link Here
636
            parse();
634
            parse();
637
        }
635
        }
638
636
639
        public CoordinationMessage(MemberImpl leader,
637
        public CoordinationMessage(Member leader,
640
                                   MemberImpl source,
638
                                   Member source,
641
                                   MemberImpl[] view,
639
                                   Member[] view,
642
                                   UniqueId id,
640
                                   UniqueId id,
643
                                   byte[] type) {
641
                                   byte[] type) {
644
            this.buf = new XByteBuffer(4096,false);
642
            this.buf = new XByteBuffer(4096,false);
Lines 655-666 Link Here
655
            return NonBlockingCoordinator.COORD_HEADER;
653
            return NonBlockingCoordinator.COORD_HEADER;
656
        }
654
        }
657
655
658
        public MemberImpl getLeader() {
656
        public Member getLeader() {
659
            if ( leader == null ) parse();
657
            if ( leader == null ) parse();
660
            return leader;
658
            return leader;
661
        }
659
        }
662
660
663
        public MemberImpl getSource() {
661
        public Member getSource() {
664
            if ( source == null ) parse();
662
            if ( source == null ) parse();
665
            return source;
663
            return source;
666
        }
664
        }
Lines 670-676 Link Here
670
            return id;
668
            return id;
671
        }
669
        }
672
670
673
        public MemberImpl[] getMembers() {
671
        public Member[] getMembers() {
674
            if ( view == null ) parse();
672
            if ( view == null ) parse();
675
            return view;
673
            return view;
676
        }
674
        }
Lines 704-710 Link Here
704
            //view
702
            //view
705
            int mbrCount = XByteBuffer.toInt(buf.getBytesDirect(),offset);
703
            int mbrCount = XByteBuffer.toInt(buf.getBytesDirect(),offset);
706
            offset += 4;
704
            offset += 4;
707
            view = new MemberImpl[mbrCount];
705
            view = new Member[mbrCount];
708
            for (int i=0; i<view.length; i++ ) {
706
            for (int i=0; i<view.length; i++ ) {
709
                int mbrLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
707
                int mbrLen = XByteBuffer.toInt(buf.getBytesDirect(),offset);
710
                offset += 4;
708
                offset += 4;
(-)java/org/apache/catalina/tribes/group/interceptors/TcpFailureDetector.java (-12 / +12 lines)
Lines 34-40 Link Here
34
import org.apache.catalina.tribes.group.InterceptorPayload;
34
import org.apache.catalina.tribes.group.InterceptorPayload;
35
import org.apache.catalina.tribes.io.ChannelData;
35
import org.apache.catalina.tribes.io.ChannelData;
36
import org.apache.catalina.tribes.io.XByteBuffer;
36
import org.apache.catalina.tribes.io.XByteBuffer;
37
import org.apache.catalina.tribes.membership.MemberImpl;
38
import org.apache.catalina.tribes.membership.Membership;
37
import org.apache.catalina.tribes.membership.Membership;
39
import org.apache.catalina.tribes.membership.StaticMember;
38
import org.apache.catalina.tribes.membership.StaticMember;
40
39
Lines 56-61 Link Here
56
 * </p>
55
 * </p>
57
 *
56
 *
58
 * @author Filip Hanik
57
 * @author Filip Hanik
58
 * @author Greg Turnquist
59
 * @version 1.0
59
 * @version 1.0
60
 */
60
 */
61
public class TcpFailureDetector extends ChannelInterceptorBase {
61
public class TcpFailureDetector extends ChannelInterceptorBase {
Lines 128-134 Link Here
128
                //if we add it here, then add it upwards too
128
                //if we add it here, then add it upwards too
129
                //check to see if it is alive
129
                //check to see if it is alive
130
                if (memberAlive(member)) {
130
                if (memberAlive(member)) {
131
                    membership.memberAlive( (MemberImpl) member);
131
                    membership.memberAlive(member);
132
                    notify = true;
132
                    notify = true;
133
                } else {
133
                } else {
134
                    addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
134
                    addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
Lines 156-162 Link Here
156
            //if the payload is not a shutdown message
156
            //if the payload is not a shutdown message
157
            if (shutdown || !memberAlive(member)) {
157
            if (shutdown || !memberAlive(member)) {
158
                //not correct, we need to maintain the map
158
                //not correct, we need to maintain the map
159
                membership.removeMember( (MemberImpl) member);
159
                membership.removeMember(member);
160
                removeSuspects.remove(member);
160
                removeSuspects.remove(member);
161
                if (member instanceof StaticMember) {
161
                if (member instanceof StaticMember) {
162
                    addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
162
                    addSuspects.put(member, Long.valueOf(System.currentTimeMillis()));
Lines 226-236 Link Here
226
        Member[] members = super.getMembers();
226
        Member[] members = super.getMembers();
227
        for (int i = 0; members != null && i < members.length; i++) {
227
        for (int i = 0; members != null && i < members.length; i++) {
228
            if (memberAlive(members[i])) {
228
            if (memberAlive(members[i])) {
229
                if (membership.memberAlive((MemberImpl)members[i])) super.memberAdded(members[i]);
229
                if (membership.memberAlive(members[i])) super.memberAdded(members[i]);
230
                addSuspects.remove(members[i]);
230
                addSuspects.remove(members[i]);
231
            } else {
231
            } else {
232
                if (membership.getMember(members[i])!=null) {
232
                if (membership.getMember(members[i])!=null) {
233
                    membership.removeMember((MemberImpl)members[i]);
233
                    membership.removeMember(members[i]);
234
                    removeSuspects.remove(members[i]);
234
                    removeSuspects.remove(members[i]);
235
                    if (members[i] instanceof StaticMember) {
235
                    if (members[i] instanceof StaticMember) {
236
                        addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
236
                        addSuspects.put(members[i], Long.valueOf(System.currentTimeMillis()));
Lines 250-271 Link Here
250
                // avoid temporary adding member.
250
                // avoid temporary adding member.
251
                continue;
251
                continue;
252
            }
252
            }
253
            if (membership.memberAlive( (MemberImpl) members[i])) {
253
            if (membership.memberAlive(members[i])) {
254
                //we don't have this one in our membership, check to see if he/she is alive
254
                //we don't have this one in our membership, check to see if he/she is alive
255
                if (memberAlive(members[i])) {
255
                if (memberAlive(members[i])) {
256
                    log.warn("Member added, even though we werent notified:" + members[i]);
256
                    log.warn("Member added, even though we werent notified:" + members[i]);
257
                    super.memberAdded(members[i]);
257
                    super.memberAdded(members[i]);
258
                } else {
258
                } else {
259
                    membership.removeMember( (MemberImpl) members[i]);
259
                    membership.removeMember(members[i]);
260
                } //end if
260
                } //end if
261
            } //end if
261
            } //end if
262
        } //for
262
        } //for
263
263
264
        //check suspect members if they are still alive,
264
        //check suspect members if they are still alive,
265
        //if not, simply issue the memberDisappeared message
265
        //if not, simply issue the memberDisappeared message
266
        MemberImpl[] keys = removeSuspects.keySet().toArray(new MemberImpl[removeSuspects.size()]);
266
        Member[] keys = removeSuspects.keySet().toArray(new Member[removeSuspects.size()]);
267
        for (int i = 0; i < keys.length; i++) {
267
        for (int i = 0; i < keys.length; i++) {
268
            MemberImpl m = keys[i];
268
            Member m = keys[i];
269
            if (membership.getMember(m) != null && (!memberAlive(m))) {
269
            if (membership.getMember(m) != null && (!memberAlive(m))) {
270
                membership.removeMember(m);
270
                membership.removeMember(m);
271
                super.memberDisappeared(m);
271
                super.memberDisappeared(m);
Lines 277-285 Link Here
277
277
278
        //check add suspects members if they are alive now,
278
        //check add suspects members if they are alive now,
279
        //if they are, simply issue the memberAdded message
279
        //if they are, simply issue the memberAdded message
280
        keys = addSuspects.keySet().toArray(new MemberImpl[addSuspects.size()]);
280
        keys = addSuspects.keySet().toArray(new Member[addSuspects.size()]);
281
        for (int i = 0; i < keys.length; i++) {
281
        for (int i = 0; i < keys.length; i++) {
282
            MemberImpl m = keys[i];
282
            Member m = keys[i];
283
            if ( membership.getMember(m) == null && (memberAlive(m))) {
283
            if ( membership.getMember(m) == null && (memberAlive(m))) {
284
                membership.memberAlive(m);
284
                membership.memberAlive(m);
285
                super.memberAdded(m);
285
                super.memberAdded(m);
Lines 292-298 Link Here
292
292
293
    protected synchronized void setupMembership() {
293
    protected synchronized void setupMembership() {
294
        if ( membership == null ) {
294
        if ( membership == null ) {
295
            membership = new Membership((MemberImpl)super.getLocalMember(true));
295
            membership = new Membership(super.getLocalMember(true));
296
        }
296
        }
297
297
298
    }
298
    }
(-)java/org/apache/catalina/tribes/io/ChannelData.java (-2 / +2 lines)
Lines 186-192 Link Here
186
            4 + //unique id length off=12
186
            4 + //unique id length off=12
187
            uniqueId.length+ //id data off=12+uniqueId.length
187
            uniqueId.length+ //id data off=12+uniqueId.length
188
            4 + //addr length off=12+uniqueId.length+4
188
            4 + //addr length off=12+uniqueId.length+4
189
            ((MemberImpl)address).getDataLength()+ //member data off=12+uniqueId.length+4+add.length
189
            address.getDataLength()+ //member data off=12+uniqueId.length+4+add.length
190
            4 + //message length off=12+uniqueId.length+4+add.length+4
190
            4 + //message length off=12+uniqueId.length+4+add.length+4
191
            message.getLength();
191
            message.getLength();
192
        return length;
192
        return length;
Lines 205-211 Link Here
205
    }
205
    }
206
206
207
    public byte[] getDataPackage(byte[] data, int offset)  {
207
    public byte[] getDataPackage(byte[] data, int offset)  {
208
        byte[] addr = ((MemberImpl)address).getData(false);
208
        byte[] addr = address.getData(false);
209
        XByteBuffer.toBytes(options,data,offset);
209
        XByteBuffer.toBytes(options,data,offset);
210
        offset += 4; //options
210
        offset += 4; //options
211
        XByteBuffer.toBytes(timestamp,data,offset);
211
        XByteBuffer.toBytes(timestamp,data,offset);
(-)java/org/apache/catalina/tribes/membership/McastServiceImpl.java (-3 / +4 lines)
Lines 46-51 Link Here
46
 * Need to fix this, could use java.nio and only need one thread to send and receive, or
46
 * Need to fix this, could use java.nio and only need one thread to send and receive, or
47
 * just use a timeout on the receive
47
 * just use a timeout on the receive
48
 * @author Filip Hanik
48
 * @author Filip Hanik
49
 * @author Greg Turnquist
49
 * @version $Id$
50
 * @version $Id$
50
 */
51
 */
51
public class McastServiceImpl
52
public class McastServiceImpl
Lines 360-366 Link Here
360
    }
361
    }
361
362
362
    private void memberDataReceived(byte[] data) {
363
    private void memberDataReceived(byte[] data) {
363
        final MemberImpl m = MemberImpl.getMember(data);
364
        final Member m = MemberImpl.getMember(data);
364
        if (log.isTraceEnabled()) log.trace("Mcast receive ping from member " + m);
365
        if (log.isTraceEnabled()) log.trace("Mcast receive ping from member " + m);
365
        Runnable t = null;
366
        Runnable t = null;
366
        if (Arrays.equals(m.getCommand(), Member.SHUTDOWN_PAYLOAD)) {
367
        if (Arrays.equals(m.getCommand(), Member.SHUTDOWN_PAYLOAD)) {
Lines 444-452 Link Here
444
    protected final Object expiredMutex = new Object();
445
    protected final Object expiredMutex = new Object();
445
    protected void checkExpired() {
446
    protected void checkExpired() {
446
        synchronized (expiredMutex) {
447
        synchronized (expiredMutex) {
447
            MemberImpl[] expired = membership.expire(timeToExpiration);
448
        	Member[] expired = membership.expire(timeToExpiration);
448
            for (int i = 0; i < expired.length; i++) {
449
            for (int i = 0; i < expired.length; i++) {
449
                final MemberImpl member = expired[i];
450
                final Member member = expired[i];
450
                if (log.isDebugEnabled())
451
                if (log.isDebugEnabled())
451
                    log.debug("Mcast expire  member " + expired[i]);
452
                    log.debug("Mcast expire  member " + expired[i]);
452
                try {
453
                try {
(-)java/org/apache/catalina/tribes/membership/MemberImpl.java (-5 / +11 lines)
Lines 32-37 Link Here
32
 * Carries the host, and port of the this or other cluster nodes.
32
 * Carries the host, and port of the this or other cluster nodes.
33
 *
33
 *
34
 * @author Filip Hanik
34
 * @author Filip Hanik
35
 * @author Greg Turnquist
35
 * @version $Id$
36
 * @version $Id$
36
 */
37
 */
37
public class MemberImpl implements Member, java.io.Externalizable {
38
public class MemberImpl implements Member, java.io.Externalizable {
Lines 170-180 Link Here
170
     * @param getalive boolean
171
     * @param getalive boolean
171
     * @return byte[]
172
     * @return byte[]
172
     */
173
     */
174
    @Override
173
    public byte[] getData(boolean getalive)  {
175
    public byte[] getData(boolean getalive)  {
174
        return getData(getalive,false);
176
        return getData(getalive,false);
175
    }
177
    }
176
178
177
179
    /**
180
     * Retrieve the total size of the message.
181
     */
182
    @Override
178
    public int getDataLength() {
183
    public int getDataLength() {
179
        return TRIBES_MBR_BEGIN.length+ //start pkg
184
        return TRIBES_MBR_BEGIN.length+ //start pkg
180
               4+ //data length
185
               4+ //data length
Lines 200-205 Link Here
200
     * @param reset boolean - reset the cached data package, and create a new one
205
     * @param reset boolean - reset the cached data package, and create a new one
201
     * @return byte[]
206
     * @return byte[]
202
     */
207
     */
208
    @Override
203
    public byte[] getData(boolean getalive, boolean reset)  {
209
    public byte[] getData(boolean getalive, boolean reset)  {
204
        if ( reset ) dataPkg = null;
210
        if ( reset ) dataPkg = null;
205
        //look in cache first
211
        //look in cache first
Lines 298-308 Link Here
298
     * @param data - the bytes received
304
     * @param data - the bytes received
299
     * @return a member object.
305
     * @return a member object.
300
     */
306
     */
301
    public static MemberImpl getMember(byte[] data, MemberImpl member) {
307
    public static Member getMember(byte[] data, MemberImpl member) {
302
        return getMember(data,0,data.length,member);
308
        return getMember(data,0,data.length,member);
303
    }
309
    }
304
310
305
    public static MemberImpl getMember(byte[] data, int offset, int length, MemberImpl member) {
311
    public static Member getMember(byte[] data, int offset, int length, MemberImpl member) {
306
        //package looks like
312
        //package looks like
307
        //start package TRIBES_MBR_BEGIN.length
313
        //start package TRIBES_MBR_BEGIN.length
308
        //package length - 4 bytes
314
        //package length - 4 bytes
Lines 408-418 Link Here
408
        return member;
414
        return member;
409
    }
415
    }
410
416
411
    public static MemberImpl getMember(byte[] data) {
417
    public static Member getMember(byte[] data) {
412
       return getMember(data,new MemberImpl());
418
       return getMember(data,new MemberImpl());
413
    }
419
    }
414
420
415
    public static MemberImpl getMember(byte[] data, int offset, int length) {
421
    public static Member getMember(byte[] data, int offset, int length) {
416
       return getMember(data,offset,length,new MemberImpl());
422
       return getMember(data,offset,length,new MemberImpl());
417
    }
423
    }
418
424
(-)java/org/apache/catalina/tribes/membership/Membership.java (-26 / +27 lines)
Lines 36-46 Link Here
36
 *
36
 *
37
 * @author Filip Hanik
37
 * @author Filip Hanik
38
 * @author Peter Rossbach
38
 * @author Peter Rossbach
39
 * @author Greg Turnquist
39
 * @version $Id$
40
 * @version $Id$
40
 */
41
 */
41
public class Membership implements Cloneable {
42
public class Membership implements Cloneable {
42
43
43
    protected static final MemberImpl[] EMPTY_MEMBERS = new MemberImpl[0];
44
    protected static final Member[] EMPTY_MEMBERS = new Member[0];
44
45
45
    private final Object membersLock = new Object();
46
    private final Object membersLock = new Object();
46
47
Lines 48-64 Link Here
48
     * The name of this membership, has to be the same as the name for the local
49
     * The name of this membership, has to be the same as the name for the local
49
     * member
50
     * member
50
     */
51
     */
51
    protected final MemberImpl local;
52
    protected final Member local;
52
53
53
    /**
54
    /**
54
     * A map of all the members in the cluster.
55
     * A map of all the members in the cluster.
55
     */
56
     */
56
    protected HashMap<MemberImpl, MbrEntry> map = new HashMap<>();
57
    protected HashMap<Member, MbrEntry> map = new HashMap<>();
57
58
58
    /**
59
    /**
59
     * A list of all the members in the cluster.
60
     * A list of all the members in the cluster.
60
     */
61
     */
61
    protected MemberImpl[] members = EMPTY_MEMBERS;
62
    protected Member[] members = EMPTY_MEMBERS;
62
63
63
    /**
64
    /**
64
      * sort members by alive time
65
      * sort members by alive time
Lines 69-77 Link Here
69
    public Object clone() {
70
    public Object clone() {
70
        synchronized (membersLock) {
71
        synchronized (membersLock) {
71
            Membership clone = new Membership(local, memberComparator);
72
            Membership clone = new Membership(local, memberComparator);
72
            final HashMap<MemberImpl, MbrEntry> tmpclone = (HashMap<MemberImpl, MbrEntry>) map.clone();
73
            final HashMap<Member, MbrEntry> tmpclone = (HashMap<Member, MbrEntry>) map.clone();
73
            clone.map = tmpclone;
74
            clone.map = tmpclone;
74
            clone.members = new MemberImpl[members.length];
75
            clone.members = new Member[members.length];
75
            System.arraycopy(members,0,clone.members,0,members.length);
76
            System.arraycopy(members,0,clone.members,0,members.length);
76
            return clone;
77
            return clone;
77
        }
78
        }
Lines 82-100 Link Here
82
     * @param local - has to be the name of the local member. Used to filter the local member from the cluster membership
83
     * @param local - has to be the name of the local member. Used to filter the local member from the cluster membership
83
     * @param includeLocal - TBA
84
     * @param includeLocal - TBA
84
     */
85
     */
85
    public Membership(MemberImpl local, boolean includeLocal) {
86
    public Membership(Member local, boolean includeLocal) {
86
        this(local, new MemberComparator(), includeLocal);
87
        this(local, new MemberComparator(), includeLocal);
87
    }
88
    }
88
89
89
    public Membership(MemberImpl local) {
90
    public Membership(Member local) {
90
        this(local, false);
91
        this(local, false);
91
    }
92
    }
92
93
93
    public Membership(MemberImpl local, Comparator<Member> comp) {
94
    public Membership(Member local, Comparator<Member> comp) {
94
        this(local, comp, false);
95
        this(local, comp, false);
95
    }
96
    }
96
97
97
    public Membership(MemberImpl local, Comparator<Member> comp, boolean includeLocal) {
98
    public Membership(Member local, Comparator<Member> comp, boolean includeLocal) {
98
        this.local = local;
99
        this.local = local;
99
        if ( includeLocal ) addMember(local);
100
        if ( includeLocal ) addMember(local);
100
        this.memberComparator = comp;
101
        this.memberComparator = comp;
Lines 115-121 Link Here
115
     * @return - true if this member is new to the cluster, false otherwise.<br/>
116
     * @return - true if this member is new to the cluster, false otherwise.<br/>
116
     * - false if this member is the local member or updated.
117
     * - false if this member is the local member or updated.
117
     */
118
     */
118
    public synchronized boolean memberAlive(MemberImpl member) {
119
    public synchronized boolean memberAlive(Member member) {
119
        boolean result = false;
120
        boolean result = false;
120
        //ignore ourselves
121
        //ignore ourselves
121
        if (  member.equals(local) ) return result;
122
        if (  member.equals(local) ) return result;
Lines 127-133 Link Here
127
            result = true;
128
            result = true;
128
       } else {
129
       } else {
129
            //update the member alive time
130
            //update the member alive time
130
            MemberImpl updateMember = entry.getMember() ;
131
            Member updateMember = entry.getMember() ;
131
            if(updateMember.getMemberAliveTime() != member.getMemberAliveTime()) {
132
            if(updateMember.getMemberAliveTime() != member.getMemberAliveTime()) {
132
                //update fields that can change
133
                //update fields that can change
133
                updateMember.setMemberAliveTime(member.getMemberAliveTime());
134
                updateMember.setMemberAliveTime(member.getMemberAliveTime());
Lines 144-155 Link Here
144
     * Add a member to this component and sort array with memberComparator
145
     * Add a member to this component and sort array with memberComparator
145
     * @param member The member to add
146
     * @param member The member to add
146
     */
147
     */
147
    public synchronized MbrEntry addMember(MemberImpl member) {
148
    public synchronized MbrEntry addMember(Member member) {
148
      synchronized (membersLock) {
149
      synchronized (membersLock) {
149
          MbrEntry entry = new MbrEntry(member);
150
          MbrEntry entry = new MbrEntry(member);
150
          if (!map.containsKey(member) ) {
151
          if (!map.containsKey(member) ) {
151
              map.put(member, entry);
152
              map.put(member, entry);
152
              MemberImpl results[] = new MemberImpl[members.length + 1];
153
              Member results[] = new Member[members.length + 1];
153
              for (int i = 0; i < members.length; i++) results[i] = members[i];
154
              for (int i = 0; i < members.length; i++) results[i] = members[i];
154
              results[members.length] = member;
155
              results[members.length] = member;
155
              members = results;
156
              members = results;
Lines 164-170 Link Here
164
     *
165
     *
165
     * @param member The member to remove
166
     * @param member The member to remove
166
     */
167
     */
167
    public void removeMember(MemberImpl member) {
168
    public void removeMember(Member member) {
168
        map.remove(member);
169
        map.remove(member);
169
        synchronized (membersLock) {
170
        synchronized (membersLock) {
170
            int n = -1;
171
            int n = -1;
Lines 175-181 Link Here
175
                }
176
                }
176
            }
177
            }
177
            if (n < 0) return;
178
            if (n < 0) return;
178
            MemberImpl results[] = new MemberImpl[members.length - 1];
179
            Member results[] = new Member[members.length - 1];
179
            int j = 0;
180
            int j = 0;
180
            for (int i = 0; i < members.length; i++) {
181
            for (int i = 0; i < members.length; i++) {
181
                if (i != n)
182
                if (i != n)
Lines 192-202 Link Here
192
     * @param maxtime - the max time a member can remain unannounced before it is considered dead.
193
     * @param maxtime - the max time a member can remain unannounced before it is considered dead.
193
     * @return the list of expired members
194
     * @return the list of expired members
194
     */
195
     */
195
    public synchronized MemberImpl[] expire(long maxtime) {
196
    public synchronized Member[] expire(long maxtime) {
196
        if(!hasMembers() )
197
        if(!hasMembers() )
197
           return EMPTY_MEMBERS;
198
           return EMPTY_MEMBERS;
198
199
199
        ArrayList<MemberImpl> list = null;
200
        ArrayList<Member> list = null;
200
        Iterator<MbrEntry> i = map.values().iterator();
201
        Iterator<MbrEntry> i = map.values().iterator();
201
        while(i.hasNext()) {
202
        while(i.hasNext()) {
202
            MbrEntry entry = i.next();
203
            MbrEntry entry = i.next();
Lines 208-214 Link Here
208
        }
209
        }
209
210
210
        if(list != null) {
211
        if(list != null) {
211
            MemberImpl[] result = new MemberImpl[list.size()];
212
            Member[] result = new Member[list.size()];
212
            list.toArray(result);
213
            list.toArray(result);
213
            for( int j=0; j<result.length; j++) {
214
            for( int j=0; j<result.length; j++) {
214
                removeMember(result[j]);
215
                removeMember(result[j]);
Lines 227-235 Link Here
227
    }
228
    }
228
229
229
230
230
    public MemberImpl getMember(Member mbr) {
231
    public Member getMember(Member mbr) {
231
        if(hasMembers()) {
232
        if(hasMembers()) {
232
            MemberImpl result = null;
233
            Member result = null;
233
            for ( int i=0; i<this.members.length && result==null; i++ ) {
234
            for ( int i=0; i<this.members.length && result==null; i++ ) {
234
                if ( members[i].equals(mbr) ) result = members[i];
235
                if ( members[i].equals(mbr) ) result = members[i];
235
            }//for
236
            }//for
Lines 247-253 Link Here
247
     * Returning a list of all the members in the membership
248
     * Returning a list of all the members in the membership
248
     * We not need a copy: add and remove generate new arrays.
249
     * We not need a copy: add and remove generate new arrays.
249
     */
250
     */
250
    public MemberImpl[] getMembers() {
251
    public Member[] getMembers() {
251
        if(hasMembers()) {
252
        if(hasMembers()) {
252
            return members;
253
            return members;
253
        } else {
254
        } else {
Lines 261-267 Link Here
261
    protected synchronized MbrEntry[] getMemberEntries()
262
    protected synchronized MbrEntry[] getMemberEntries()
262
    {
263
    {
263
        MbrEntry[] result = new MbrEntry[map.size()];
264
        MbrEntry[] result = new MbrEntry[map.size()];
264
        Iterator<Map.Entry<MemberImpl,MbrEntry>> i = map.entrySet().iterator();
265
        Iterator<Map.Entry<Member,MbrEntry>> i = map.entrySet().iterator();
265
        int pos = 0;
266
        int pos = 0;
266
        while ( i.hasNext() )
267
        while ( i.hasNext() )
267
            result[pos++] = i.next().getValue();
268
            result[pos++] = i.next().getValue();
Lines 293-302 Link Here
293
     */
294
     */
294
    protected static class MbrEntry {
295
    protected static class MbrEntry {
295
296
296
        protected final MemberImpl mbr;
297
        protected final Member mbr;
297
        protected long lastHeardFrom;
298
        protected long lastHeardFrom;
298
299
299
        public MbrEntry(MemberImpl mbr) {
300
        public MbrEntry(Member mbr) {
300
           this.mbr = mbr;
301
           this.mbr = mbr;
301
        }
302
        }
302
303
Lines 310-316 Link Here
310
        /**
311
        /**
311
         * Return the actual Member object
312
         * Return the actual Member object
312
         */
313
         */
313
        public MemberImpl getMember() {
314
        public Member getMember() {
314
            return mbr;
315
            return mbr;
315
        }
316
        }
316
317
(-)java/org/apache/catalina/tribes/util/Arrays.java (-3 / +4 lines)
Lines 30-35 Link Here
30
30
31
/**
31
/**
32
 * @author Filip Hanik
32
 * @author Filip Hanik
33
 * @author Greg Turnquist
33
 * @version 1.0
34
 * @version 1.0
34
 */
35
 */
35
public class Arrays {
36
public class Arrays {
Lines 152-163 Link Here
152
    }
153
    }
153
154
154
    public static void fill(Membership mbrship, Member[] m) {
155
    public static void fill(Membership mbrship, Member[] m) {
155
        for (int i=0; i<m.length; i++ ) mbrship.addMember((MemberImpl)m[i]);
156
        for (int i=0; i<m.length; i++ ) mbrship.addMember(m[i]);
156
    }
157
    }
157
158
158
    public static Member[] diff(Membership complete, Membership local, MemberImpl ignore) {
159
    public static Member[] diff(Membership complete, Membership local, Member ignore) {
159
        ArrayList<Member> result = new ArrayList<>();
160
        ArrayList<Member> result = new ArrayList<>();
160
        MemberImpl[] comp = complete.getMembers();
161
        Member[] comp = complete.getMembers();
161
        for ( int i=0; i<comp.length; i++ ) {
162
        for ( int i=0; i<comp.length; i++ ) {
162
            if ( ignore!=null && ignore.equals(comp[i]) ) continue;
163
            if ( ignore!=null && ignore.equals(comp[i]) ) continue;
163
            if ( local.getMember(comp[i]) == null ) result.add(comp[i]);
164
            if ( local.getMember(comp[i]) == null ) result.add(comp[i]);
(-)test/org/apache/catalina/tribes/demos/ChannelCreator.java (-1 / +2 lines)
Lines 48-53 Link Here
48
 * <p>Company: </p>
48
 * <p>Company: </p>
49
 *
49
 *
50
 * @author fhanik
50
 * @author fhanik
51
 * @author Greg Turnquist
51
 * @version 1.0
52
 * @version 1.0
52
 */
53
 */
53
public class ChannelCreator {
54
public class ChannelCreator {
Lines 133-139 Link Here
133
                String d = args[++i];
134
                String d = args[++i];
134
                String h = d.substring(0,d.indexOf(":"));
135
                String h = d.substring(0,d.indexOf(":"));
135
                String p = d.substring(h.length()+1);
136
                String p = d.substring(h.length()+1);
136
                MemberImpl m = new MemberImpl(h,Integer.parseInt(p),2000);
137
                Member m = new MemberImpl(h,Integer.parseInt(p),2000);
137
                staticMembers.add(m);
138
                staticMembers.add(m);
138
            } else if ("-throughput".equals(args[i])) {
139
            } else if ("-throughput".equals(args[i])) {
139
                throughput = true;
140
                throughput = true;
(-)test/org/apache/catalina/tribes/membership/TestMemberImplSerialization.java (-9 / +10 lines)
Lines 16-26 Link Here
16
 */
16
 */
17
package org.apache.catalina.tribes.membership;
17
package org.apache.catalina.tribes.membership;
18
18
19
import java.util.Arrays;
20
21
import static org.junit.Assert.assertFalse;
19
import static org.junit.Assert.assertFalse;
22
import static org.junit.Assert.assertTrue;
20
import static org.junit.Assert.assertTrue;
23
21
22
import java.util.Arrays;
23
24
import org.apache.catalina.tribes.Member;
24
import org.junit.Before;
25
import org.junit.Before;
25
import org.junit.Test;
26
import org.junit.Test;
26
27
Lines 73-80 Link Here
73
        byte[] md1 = m1.getData();
74
        byte[] md1 = m1.getData();
74
        byte[] md2 = m2.getData();
75
        byte[] md2 = m2.getData();
75
76
76
        MemberImpl a1 = MemberImpl.getMember(md1);
77
        Member a1 = MemberImpl.getMember(md1);
77
        MemberImpl a2 = MemberImpl.getMember(md2);
78
        Member a2 = MemberImpl.getMember(md2);
78
79
79
        assertTrue(a1.getUdpPort()==a2.getUdpPort());
80
        assertTrue(a1.getUdpPort()==a2.getUdpPort());
80
        assertTrue(a1.getUdpPort()==udpPort);
81
        assertTrue(a1.getUdpPort()==udpPort);
Lines 82-94 Link Here
82
83
83
    @Test
84
    @Test
84
    public void testSerializationOne() throws Exception {
85
    public void testSerializationOne() throws Exception {
85
        MemberImpl m = m1;
86
    	Member m = m1;
86
        byte[] md1 = m.getData(false,true);
87
        byte[] md1 = m.getData(false,true);
87
        byte[] mda1 = m.getData(false,false);
88
        byte[] mda1 = m.getData(false,false);
88
        assertTrue(Arrays.equals(md1,mda1));
89
        assertTrue(Arrays.equals(md1,mda1));
89
        assertTrue(md1==mda1);
90
        assertTrue(md1==mda1);
90
        mda1 = m.getData(true,true);
91
        mda1 = m.getData(true,true);
91
        MemberImpl ma1 = MemberImpl.getMember(mda1);
92
        Member ma1 = MemberImpl.getMember(mda1);
92
        assertTrue(compareMembers(m,ma1));
93
        assertTrue(compareMembers(m,ma1));
93
        mda1 = p1.getData(false);
94
        mda1 = p1.getData(false);
94
        assertFalse(Arrays.equals(md1,mda1));
95
        assertFalse(Arrays.equals(md1,mda1));
Lines 98-112 Link Here
98
        md1 = m.getData(true,true);
99
        md1 = m.getData(true,true);
99
        Thread.sleep(50);
100
        Thread.sleep(50);
100
        mda1 = m.getData(true,true);
101
        mda1 = m.getData(true,true);
101
        MemberImpl a1 = MemberImpl.getMember(md1);
102
        Member a1 = MemberImpl.getMember(md1);
102
        MemberImpl a2 = MemberImpl.getMember(mda1);
103
        Member a2 = MemberImpl.getMember(mda1);
103
        assertTrue(a1.equals(a2));
104
        assertTrue(a1.equals(a2));
104
        assertFalse(Arrays.equals(md1,mda1));
105
        assertFalse(Arrays.equals(md1,mda1));
105
106
106
107
107
    }
108
    }
108
109
109
    public boolean compareMembers(MemberImpl impl1, MemberImpl impl2) {
110
    public boolean compareMembers(Member impl1, Member impl2) {
110
        boolean result = true;
111
        boolean result = true;
111
        result = result && Arrays.equals(impl1.getHost(),impl2.getHost());
112
        result = result && Arrays.equals(impl1.getHost(),impl2.getHost());
112
        result = result && Arrays.equals(impl1.getPayload(),impl2.getPayload());
113
        result = result && Arrays.equals(impl1.getPayload(),impl2.getPayload());
(-)test/org/apache/catalina/tribes/test/NioSenderTest.java (-1 / +1 lines)
Lines 40-46 Link Here
40
public class NioSenderTest {
40
public class NioSenderTest {
41
    private Selector selector = null;
41
    private Selector selector = null;
42
    private int counter = 0;
42
    private int counter = 0;
43
    MemberImpl mbr;
43
    Member mbr;
44
    private static int testOptions = Channel.SEND_OPTIONS_DEFAULT;
44
    private static int testOptions = Channel.SEND_OPTIONS_DEFAULT;
45
    public NioSenderTest()  {
45
    public NioSenderTest()  {
46
        // Default constructor
46
        // Default constructor

Return to bug 54330