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

« back to all changes in this revision

Viewing changes to src/main/java/net/sf/ehcache/distribution/MulticastKeepaliveHeartbeatSender.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.
46
46
 * You can also control how often the heartbeat sends by setting the interval.
47
47
 *
48
48
 * @author Greg Luck
49
 
 * @version $Id: MulticastKeepaliveHeartbeatSender.java 2358 2010-04-30 02:28:26Z gluck $
 
49
 * @version $Id: MulticastKeepaliveHeartbeatSender.java 6490 2012-10-30 18:21:49Z cdennis $
50
50
 */
51
51
public final class MulticastKeepaliveHeartbeatSender {
52
52
 
56
56
    private static final int DEFAULT_HEARTBEAT_INTERVAL = 5000;
57
57
    private static final int MINIMUM_HEARTBEAT_INTERVAL = 1000;
58
58
    private static final int MAXIMUM_PEERS_PER_SEND = 150;
 
59
    private static final int ONE_HUNDRED_MS = 100;
59
60
 
60
61
    private static long heartBeatInterval = DEFAULT_HEARTBEAT_INTERVAL;
 
62
    private static long heartBeatStaleTime = -1;
61
63
 
62
64
    private final InetAddress groupMulticastAddress;
63
65
    private final Integer groupMulticastPort;
273
275
    }
274
276
 
275
277
    /**
 
278
     * Sets the heartbeat stale time to something other than the default of {@code ((2 * HeartBeatInterval) + 100)ms}.
 
279
     * This is useful for testing, but not recommended for production. This method is static and so affects the stale
 
280
     * time all users.
 
281
     *
 
282
     * @param heartBeatStaleTime a time in ms
 
283
     */
 
284
    public static void setHeartBeatStaleTime(long heartBeatStaleTime) {
 
285
        MulticastKeepaliveHeartbeatSender.heartBeatStaleTime = heartBeatStaleTime;
 
286
    }
 
287
 
 
288
    /**
276
289
     * Returns the heartbeat interval.
277
290
     */
278
291
    public static long getHeartBeatInterval() {
280
293
    }
281
294
 
282
295
    /**
 
296
     * Returns the time after which a heartbeat is considered stale.
 
297
     */
 
298
    public static long getHeartBeatStaleTime() {
 
299
        if (heartBeatStaleTime < 0) {
 
300
            return (heartBeatInterval * 2) + ONE_HUNDRED_MS;
 
301
        } else {
 
302
            return heartBeatStaleTime;
 
303
        }
 
304
    }
 
305
 
 
306
    /**
283
307
     * @return the TTL
284
308
     */
285
309
    public Integer getTimeToLive() {