~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/main/java/net/sf/ehcache/terracotta/TerracottaCacheCluster.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 *  Copyright 2003-2010 Terracotta, Inc.
 
2
 *  Copyright Terracotta, Inc.
3
3
 *
4
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
5
 *  you may not use this file except in compliance with the License.
16
16
 
17
17
package net.sf.ehcache.terracotta;
18
18
 
19
 
import java.net.InetAddress;
20
 
import java.net.UnknownHostException;
21
19
import java.util.Collection;
22
20
import java.util.HashSet;
23
21
import java.util.List;
71
69
     * Fire Rejoin event to all listeners.
72
70
     * Package protected method
73
71
     *
74
 
     * @param clusterNode
75
72
     * @param oldNode
 
73
     * @param newNode
76
74
     */
77
75
    void fireNodeRejoinedEvent(ClusterNode oldNode, ClusterNode newNode) {
78
76
        Set<ClusterTopologyListener> firedToListeners = new HashSet<ClusterTopologyListener>();
90
88
 
91
89
    private void fireRejoinEvent(ClusterNode oldNode, ClusterNode newNode, ClusterTopologyListener listener) {
92
90
        try {
93
 
            listener.clusterRejoined(new DisconnectedClusterNode(oldNode), newNode);
 
91
            listener.clusterRejoined(oldNode, newNode);
94
92
        } catch (Throwable e) {
95
93
            LOGGER.error("Caught exception while firing rejoin event", e);
96
94
        }
168
166
    }
169
167
 
170
168
    /**
171
 
     * Until fixed in terracotta core, getHostName() and getIp() does not work after node has disconnected.
172
 
     * Temporary fix for beta release.
173
 
     *
174
 
     */
175
 
    private static class DisconnectedClusterNode implements ClusterNode {
176
 
 
177
 
        private final ClusterNode delegateNode;
178
 
 
179
 
        /**
180
 
         * Constructor accepting the actual delegate node
181
 
         *
182
 
         * @param actualNode
183
 
         */
184
 
        public DisconnectedClusterNode(final ClusterNode actualNode) {
185
 
            this.delegateNode = actualNode;
186
 
        }
187
 
 
188
 
        /**
189
 
         * {@inheritDoc}
190
 
         */
191
 
        public String getId() {
192
 
            return delegateNode.getId();
193
 
        }
194
 
 
195
 
        /**
196
 
         * {@inheritDoc}
197
 
         */
198
 
        public String getHostname() {
199
 
            String hostName = "";
200
 
            try {
201
 
                hostName = InetAddress.getLocalHost().getHostName();
202
 
            } catch (UnknownHostException e) {
203
 
                hostName = "[Can't determine hostname and " + delegateNode.getId() + " has DISCONNECTED]";
204
 
            }
205
 
            return hostName;
206
 
        }
207
 
 
208
 
        /**
209
 
         * {@inheritDoc}
210
 
         */
211
 
        public String getIp() {
212
 
            String ip = "";
213
 
            try {
214
 
                ip = InetAddress.getLocalHost().getHostAddress();
215
 
            } catch (UnknownHostException e) {
216
 
                ip = "[Can't determine IP and " + delegateNode.getId() + " has DISCONNECTED]";
217
 
            }
218
 
            return ip;
219
 
        }
220
 
 
221
 
    }
222
 
 
223
 
    /**
224
169
     * {@inheritDoc}
225
170
     */
226
171
    public List<ClusterTopologyListener> getTopologyListeners() {