View Javadoc

1   /*
2    * Copyright (c) 1998-2002 The Jgroup Team.
3    *
4    * This program is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU Lesser General Public License version 2 as
6    * published by the Free Software Foundation.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Lesser General Public License for more details.
12   *
13   * You should have received a copy of the GNU Lesser General Public License
14   * along with this program; if not, write to the Free Software
15   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16   *
17   */
18  
19  package jgroup.relacs.gm;
20  
21  import jgroup.core.IID;
22  
23  /**
24   *  The <code>LeaseInfo</code> class is a datastructure used by the
25   *  dependable registry to support leasing.
26   *
27   *  @author Henning Hommeland
28   *  @author Jo Andreas Lind
29   *  @since Jgroup 2.1
30   */
31  public class LeaseInfo
32  {
33    //////////////////////////////////////////////////////////////////////////////////////////
34    // Private fields
35    //////////////////////////////////////////////////////////////////////////////////////////
36  
37    /* A table of IIDs */
38    private IID iid[];
39    
40    /* A table of timestamps */
41    private long timestamp[];
42    
43    /* Size of tables */
44    private int size;
45    
46    /*  */
47    private long leasetime;
48  
49  
50    //////////////////////////////////////////////////////////////////////////////////////////
51    // Constructor
52    //////////////////////////////////////////////////////////////////////////////////////////	
53    
54    public LeaseInfo(int size)
55    {
56  	iid = new IID[size];
57  	timestamp = new long[size];
58  	this.size = size;
59    }
60    
61    
62    //////////////////////////////////////////////////////////////////////////////////////////
63    // Class methods
64    //////////////////////////////////////////////////////////////////////////////////////////
65  	
66    public void setTimeStamp(long ts, int place)
67    {
68  	this.timestamp[place] = ts;
69    }
70  
71    public void setIID(IID iid, int place)
72    {
73      this.iid[place] = iid;
74    }
75  
76    public IID getIID(int place)
77    {
78  	return iid[place];
79    }
80  	
81    public int size()
82    {
83  	return size;
84    }
85  	
86    public long getLeasetime()
87    {
88  	return leasetime;
89    }
90  	
91    public void setLeasetime(long rr)
92    {
93  	this.leasetime = rr;
94    }
95  
96  
97    /**
98     *  Returns true if the lease has expired for the member given by
99     *  position argument <code>j</code>.  Otherwise, false is returned.
100    */
101   public boolean leaseExpired(int j)
102   {
103     return (System.currentTimeMillis() - timestamp[j]) > leasetime;
104   }
105 
106 } // End LeaseInfo
107