KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > mailslot > MailSlot


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb.mailslot;
18
19 import org.alfresco.filesys.util.DataPacker;
20
21 /**
22  * Mail slot constants class.
23  */

24 public final class MailSlot
25 {
26
27     // Mail slot opcodes
28

29     public static final int WRITE = 0x01;
30
31     // Mail slot classes
32

33     public static final int UNRELIABLE = 0x02;
34
35     // Mailslot \MAILSLOT\BROWSE opcodes
36

37     public static final int HostAnnounce = 1;
38     public static final int AnnouncementRequest = 2;
39     public static final int RequestElection = 8;
40     public static final int GetBackupListReq = 9;
41     public static final int GetBackupListResp = 10;
42     public static final int BecomeBackup = 11;
43     public static final int DomainAnnouncement = 12;
44     public static final int MasterAnnouncement = 13;
45     public static final int LocalMasterAnnouncement = 15;
46
47     /**
48      * Create a host announcement mailslot structure
49      *
50      * @param buf byte[]
51      * @param off int
52      * @param host String
53      * @param comment String
54      * @param typ int
55      * @param interval int
56      * @param upd int
57      * @return int
58      */

59     public final static int createHostAnnouncement(byte[] buf, int off, String JavaDoc host, String JavaDoc comment, int typ,
60             int interval, int upd)
61     {
62
63         // Set the command code and update count
64

65         buf[off] = MailSlot.HostAnnounce;
66         buf[off + 1] = 0; // (byte) (upd & 0xFF);
67

68         // Set the announce interval, in minutes
69

70         DataPacker.putIntelInt(interval * 60000, buf, off + 2);
71
72         // Pack the host name
73

74         byte[] hostByt = host.getBytes();
75         for (int i = 0; i < 16; i++)
76         {
77             if (i < hostByt.length)
78                 buf[off + 6 + i] = hostByt[i];
79             else
80                 buf[off + 6 + i] = 0;
81         }
82
83         // Major/minor version number
84

85         buf[off + 22] = 5; // major version
86
buf[off + 23] = 1; // minor version
87

88         // Set the server type flags
89

90         DataPacker.putIntelInt(typ, buf, off + 24);
91
92         // Browser election version and browser constant
93

94         DataPacker.putIntelShort(0x010F, buf, off + 28);
95         DataPacker.putIntelShort(0xAA55, buf, off + 30);
96
97         // Add the server comment string, or a null string
98

99         int pos = off + 33;
100
101         if (comment != null)
102             pos = DataPacker.putString(comment, buf, off + 32, true);
103
104         // Return the end of data position
105

106         return pos;
107     }
108
109     /**
110      * Create an announcement request mailslot structure
111      *
112      * @param buf byte[]
113      * @param off int
114      * @param host String
115      * @return int
116      */

117     public final static int createAnnouncementRequest(byte[] buf, int off, String JavaDoc host)
118     {
119
120         // Set the command code
121

122         buf[off] = MailSlot.AnnouncementRequest;
123         buf[off + 1] = 0;
124
125         // Pack the host name
126

127         byte[] hostByt = host.getBytes();
128         for (int i = 0; i < 16; i++)
129         {
130             if (i < hostByt.length)
131                 buf[off + 2 + i] = hostByt[i];
132             else
133                 buf[off + 2 + i] = 0;
134         }
135
136         // Return the end of buffer position
137

138         return off + 17;
139     }
140 }
Popular Tags