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 16 public class DenyResponseHeader extends Header { 17 18 public static final String HEADER_KEY = "denyResponseHeader"; 19 20 public static final int NONE = 0; 21 22 public static final int LEASE_DENIED = 1; 23 24 public static final int RENEW_DENIED = 2; 25 26 public static final int CANCEL_DENIED = 3; 27 28 private int headerType; 29 30 private String denialReason; 31 32 private Object tenant; 33 34 40 public DenyResponseHeader() { 41 this.headerType = NONE; 42 this.denialReason = null; 43 } 44 45 49 public DenyResponseHeader(int headerType, String denialReason, Object tenant) { 50 51 boolean correctHeaderType = 53 (headerType == LEASE_DENIED) || 54 (headerType == RENEW_DENIED) || 55 (headerType == CANCEL_DENIED); 56 57 if (!correctHeaderType) 58 throw new IllegalArgumentException ( 59 "Only LEASE_DENIED or RENEW_DENIED types " + 60 "are allowed in this constructor."); 61 62 this.headerType = headerType; 63 this.denialReason = denialReason; 64 this.tenant = tenant; 65 } 66 67 70 public int getType() { 71 return headerType; 72 } 73 74 77 public String getDenialReason() { 78 return denialReason; 79 } 80 81 84 public Object getTenant() { 85 return tenant; 86 } 87 88 91 public void readExternal(ObjectInput in) 92 throws IOException , ClassNotFoundException 93 { 94 headerType = in.readInt(); 95 denialReason = in.readUTF(); 96 tenant = in.readObject(); 97 } 98 99 102 public void writeExternal(ObjectOutput out) 103 throws IOException 104 { 105 out.writeInt(headerType); 106 out.writeUTF(denialReason); 107 out.writeObject(tenant); 108 } 109 110 } | Popular Tags |