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 18 public class LeaseResponseHeader extends Header { 19 20 public static final String HEADER_KEY = "leaseResponseHeader"; 21 22 public static final int NONE = 0; 23 24 public static final int LEASE_GRANTED = 1; 25 26 public static final int LEASE_RENEWED = 2; 27 28 public static final int LEASE_CANCELED = 3; 29 30 private int headerType; 31 32 private long duration; 33 34 private boolean isAbsolute; 35 36 private Object tenant; 37 38 44 public LeaseResponseHeader() { 45 headerType = NONE; 46 duration = -1; 47 isAbsolute = false; 48 } 49 50 54 public LeaseResponseHeader(int headerType, Object tenant) { 55 56 boolean correctHeaderType = 57 (headerType == LEASE_CANCELED); 58 59 if (!correctHeaderType) 60 throw new IllegalArgumentException ( 61 "Only LEASE_CANCELED type " + 62 "is allowed in this constructor."); 63 64 this.headerType = headerType; 65 this.tenant = tenant; 66 } 67 68 69 73 public LeaseResponseHeader(int headerType, long duration, boolean isAbsolute, Object tenant) { 74 75 boolean correctHeaderType = 76 (headerType == LEASE_GRANTED) || 77 (headerType == LEASE_RENEWED); 78 79 if (!correctHeaderType) 80 throw new IllegalArgumentException ( 81 "Only LEASE_GRANTED or LEASE_RENEWED types " + 82 "are allowed in this constructor."); 83 84 this.headerType = headerType; 85 this.duration = duration; 86 this.isAbsolute = isAbsolute; 87 this.tenant = tenant; 88 } 89 90 93 public int getType() { 94 return headerType; 95 } 96 97 102 public long getDuration() { 103 return duration; 104 } 105 106 112 public boolean isAbsolute() { 113 return isAbsolute; 114 } 115 116 119 public Object getTenant() { 120 return tenant; 121 } 122 123 126 public void readExternal(ObjectInput in) 127 throws IOException , ClassNotFoundException 128 { 129 headerType = in.readInt(); 130 131 duration = in.readLong(); 132 isAbsolute = in.readBoolean(); 133 134 tenant = in.readObject(); 135 } 136 137 140 public void writeExternal(ObjectOutput out) 141 throws IOException 142 { 143 out.writeInt(headerType); 144 145 out.writeLong(duration); 146 out.writeBoolean(isAbsolute); 147 148 out.writeObject(tenant); 149 } 150 151 152 } | Popular Tags |