1 package org.jgroups.service.lease; 2 3 import org.jgroups.Header; 4 5 import java.io.IOException ; 6 import java.io.ObjectInput ; 7 import java.io.ObjectOutput ; 8 9 17 public class LeaseRequestHeader extends Header { 18 19 public static final String HEADER_KEY = "leaseRequestHeader"; 20 21 private static final int NONE = 0; 22 23 public static final int NEW_LEASE_REQUEST = 1; 24 25 public static final int RENEW_LEASE_REQUEST = 2; 26 27 public static final int CANCEL_LEASE_REQUEST = 3; 28 29 30 private int headerType; 31 32 private long duration; 33 34 private boolean isAbsolute; 35 36 private Object tenant; 37 38 44 public LeaseRequestHeader() { 45 headerType = NONE; 46 duration = -1; 47 isAbsolute = false; 48 tenant = null; 49 } 50 51 55 public LeaseRequestHeader(int headerType, long duration, 56 boolean isAbsolute, Object tenant) 57 { 58 if (headerType < 1 || headerType > 3) 59 throw new IllegalArgumentException ( 60 "Unknown header type " + headerType); 61 62 this.headerType = headerType; 63 this.duration = duration; 64 this.isAbsolute = isAbsolute; 65 this.tenant = tenant; 66 } 67 68 71 public int getType() { 72 return headerType; 73 } 74 75 81 public long getDuration() { 82 return duration; 83 } 84 85 92 public boolean isAbsolute() { 93 return isAbsolute; 94 } 95 96 101 public Object getTenant() { 102 return tenant; 103 } 104 105 115 public void readExternal(ObjectInput in) 116 throws IOException , ClassNotFoundException 117 { 118 headerType = in.readInt(); 119 120 if (headerType != CANCEL_LEASE_REQUEST) { 121 duration = in.readLong(); 122 isAbsolute = in.readBoolean(); 123 } 124 125 tenant = in.readObject(); 126 } 127 128 138 public void writeExternal(ObjectOutput out) 139 throws IOException 140 { 141 out.writeInt(headerType); 142 143 if (headerType != CANCEL_LEASE_REQUEST) { 144 out.writeLong(duration); 145 out.writeBoolean(isAbsolute); 146 } 147 148 out.writeObject(tenant); 149 } 150 151 } | Popular Tags |