001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina.tribes.transport;
019:
020: import org.apache.catalina.tribes.Member;
021: import java.util.HashMap;
022:
023: /**
024: *
025: * @author Filip Hanik
026: * @version 1.0
027: * @since 5.5.16
028: */
029:
030: public class SenderState {
031:
032: public static final int READY = 0;
033: public static final int SUSPECT = 1;
034: public static final int FAILING = 2;
035: /**
036: * The descriptive information about this implementation.
037: */
038: private static final String info = "SenderState/1.0";
039:
040: protected static HashMap memberStates = new HashMap();
041:
042: public static SenderState getSenderState(Member member) {
043: return getSenderState(member, true);
044: }
045:
046: public static SenderState getSenderState(Member member,
047: boolean create) {
048: SenderState state = (SenderState) memberStates.get(member);
049: if (state == null && create) {
050: synchronized (memberStates) {
051: state = (SenderState) memberStates.get(member);
052: if (state == null) {
053: state = new SenderState();
054: memberStates.put(member, state);
055: }
056: }
057: }
058: return state;
059: }
060:
061: public static void removeSenderState(Member member) {
062: synchronized (memberStates) {
063: memberStates.remove(member);
064: }
065: }
066:
067: // ----------------------------------------------------- Instance Variables
068:
069: private int state = READY;
070:
071: // ----------------------------------------------------- Constructor
072:
073: private SenderState() {
074: this (READY);
075: }
076:
077: private SenderState(int state) {
078: this .state = state;
079: }
080:
081: /**
082: *
083: * @return boolean
084: */
085: public boolean isSuspect() {
086: return (state == SUSPECT) || (state == FAILING);
087: }
088:
089: public void setSuspect() {
090: state = SUSPECT;
091: }
092:
093: public boolean isReady() {
094: return state == READY;
095: }
096:
097: public void setReady() {
098: state = READY;
099: }
100:
101: public boolean isFailing() {
102: return state == FAILING;
103: }
104:
105: public void setFailing() {
106: state = FAILING;
107: }
108:
109: // ----------------------------------------------------- Public Properties
110:
111: }
|