NodeImpl xref

View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activecluster.impl;
    19
    20  import org.codehaus.activecluster.Node;
    21
    22  import javax.jms.Destination;
    23  import java.util.HashMap;
    24  import java.util.Map;
    25
    26
    27  /***
    28   * Default implementation of a remote Node
    29   *
    30   * @version $Revision: 1.6 $
    31   */
    32  public class NodeImpl implements Node {
    33
    34      private Destination destination;
    35      protected Map state;
    36      protected boolean coordinator;
    37
    38      /***
    39       * Allow a node to be copied for sending it as a message
    40       *
    41       * @param node
    42       */
    43      public NodeImpl(Node node) {
    44          this(node.getDestination(), node.getState());
    45      }
    46
    47      public NodeImpl(Destination destination) {
    48          this(destination, new HashMap());
    49      }
    50
    51      public NodeImpl(Destination destination, Map state) {
    52          this.destination = destination;
    53          this.state = state;
    54      }
    55
    56      /***
    57       * @return the name of the node
    58       */
    59      public String getName() {
    60          return destination.toString();
    61      }
    62
    63      public String toString() {
    64          return "Node[destination: " + destination + " state: " + state + "]";
    65      }
    66
    67      public Destination getDestination() {
    68          return destination;
    69      }
    70
    71      public synchronized Map getState() {
    72          return new HashMap(state);
    73      }
    74
    75
    76      protected synchronized void setState(Map state) {
    77          this.state = state;
    78      }
    79
    80
    81      /***
    82       * @return true if this node has been elected as coordinator
    83       */
    84      public boolean isCoordinator() {
    85          return coordinator;
    86      }
    87
    88      protected void setCoordinator(boolean value) {
    89          coordinator = value;
    90      }
    91  }