Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / lang / java / src / com / sleepycat / db / ReplicationChannel.java
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2011, 2012 Oracle and/or its affiliates.  All rights reserved.
5  *
6  * $Id$
7  */
8
9 package com.sleepycat.db;
10
11 import com.sleepycat.db.internal.DbChannel;
12
13 /**
14 A ReplicationChannel handle is used to manage a channel in a replication group.
15 ReplicationChannel handles are opened using the {@link com.sleepycat.db.Environment#openChannel Environment.openChannel} method.
16 */
17 public class ReplicationChannel {
18     private DbChannel chan;
19
20     /* package */
21     ReplicationChannel(final DbChannel chan) {
22         this.chan = chan;
23     }
24
25     /**
26     Close the channel.
27     */
28     public void close()
29         throws DatabaseException {
30
31         this.chan.close(0);
32     }
33
34     /**
35     Send a message on the message channel asynchronously.
36     <p>
37     @param messages
38     */
39     public void sendMessage(java.util.Set messages) 
40         throws DatabaseException {
41
42         DatabaseEntry[] msgs = (DatabaseEntry[])messages.toArray();
43         this.chan.send_repmsg(msgs, msgs.length, 0);
44     }
45
46     /**
47     Send request on the message channel. It blocks waiting for a response 
48     before returning.
49     <p>
50     @param messages
51     @param response
52     @param timeout
53     */
54     public void sendRequest(
55         java.util.Set messages, DatabaseEntry response, long timeout) 
56         throws DatabaseException {
57
58         DatabaseEntry[] msgs = (DatabaseEntry[])messages.toArray();
59         this.chan.send_request(msgs, msgs.length, response, timeout, 0);
60     }
61
62     /**
63     Sets the default timeout value for the channel.
64     <p>
65     @param timeout
66     */
67     public void setTimeout(long timeout) 
68         throws DatabaseException {
69
70         this.chan.set_timeout(timeout);
71     }
72 }