KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > service > lease > DenyResponseHeader


1 package org.jgroups.service.lease;
2
3 import org.jgroups.Header;
4
5 import java.io.IOException JavaDoc;
6 import java.io.ObjectInput JavaDoc;
7 import java.io.ObjectOutput JavaDoc;
8
9 /**
10  * Message header that represents deny response. This header contains denial
11  * reason and entity that requested a lease. This allows redirect response
12  * on client side to that entity.
13  *
14  * @author Roman Rokytskyy (rrokytskyy@acm.org)
15  */

16 public class DenyResponseHeader extends Header {
17     
18     public static final String JavaDoc 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 JavaDoc denialReason;
31     
32     private Object JavaDoc tenant;
33     
34     /**
35      * Create uninitialized instance of this class. This constructor is used
36      * for implementation of {@link java.io.Externalizable} interface. There
37      * is no other way to set state of this object except reading it from
38      * object input using {@link #readExternal(java.io.ObjectInput)} method.
39      */

40     public DenyResponseHeader() {
41     this.headerType = NONE;
42     this.denialReason = null;
43     }
44     
45     /**
46      * Create instance of this class for specified denial type and denial
47      * reason.
48      */

49     public DenyResponseHeader(int headerType, String JavaDoc denialReason, Object JavaDoc tenant) {
50     
51     // check if header type is correct
52
boolean correctHeaderType =
53         (headerType == LEASE_DENIED) ||
54         (headerType == RENEW_DENIED) ||
55         (headerType == CANCEL_DENIED);
56         
57     if (!correctHeaderType)
58         throw new IllegalArgumentException JavaDoc(
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     /**
68      * Get type of lease request.
69      */

70     public int getType() {
71     return headerType;
72     }
73
74     /**
75      * Get reason why lease was denied.
76      */

77     public String JavaDoc getDenialReason() {
78     return denialReason;
79     }
80     
81     /**
82      * Get tenant to which this response is addressed to
83      */

84     public Object JavaDoc getTenant() {
85     return tenant;
86     }
87
88     /**
89      * Read state of this object from object input.
90      */

91     public void readExternal(ObjectInput JavaDoc in)
92     throws IOException JavaDoc, ClassNotFoundException JavaDoc
93     {
94     headerType = in.readInt();
95         denialReason = in.readUTF();
96     tenant = in.readObject();
97     }
98
99     /**
100      * Write state of this object into object output.
101      */

102     public void writeExternal(ObjectOutput JavaDoc out)
103     throws IOException JavaDoc
104     {
105     out.writeInt(headerType);
106         out.writeUTF(denialReason);
107     out.writeObject(tenant);
108     }
109     
110 }
Popular Tags