summaryrefslogtreecommitdiff
path: root/lang/java/src/com/sleepycat/db/ReplicationChannel.java
blob: 366a47b20bcfc7db5dcb45e4be781100bc9cd67f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2011, 2015 Oracle and/or its affiliates.  All rights reserved.
 *
 * $Id$
 */

package com.sleepycat.db;

import com.sleepycat.db.internal.DbChannel;

/**
A ReplicationChannel handle is used to manage a channel in a replication group.
ReplicationChannel handles are opened using the {@link com.sleepycat.db.Environment#openChannel Environment.openChannel} method.
*/
public class ReplicationChannel {
    private DbChannel chan;

    /* package */
    ReplicationChannel(final DbChannel chan) {
	this.chan = chan;
    }

    /**
    Close the channel.
    */
    public void close()
        throws DatabaseException {

        this.chan.close(0);
    }

    /**
    Send a message on the message channel asynchronously.
    <p>
    @param messages
    */
    public void sendMessage(java.util.Set messages) 
        throws DatabaseException {

        DatabaseEntry[] msgs = (DatabaseEntry[])messages.toArray();
        this.chan.send_repmsg(msgs, msgs.length, 0);
    }

    /**
    Send request on the message channel. It blocks waiting for a response 
    before returning.
    <p>
    @param messages
    @param response
    @param timeout
    */
    public void sendRequest(
        java.util.Set messages, DatabaseEntry response, long timeout) 
        throws DatabaseException {

        DatabaseEntry[] msgs = (DatabaseEntry[])messages.toArray();
        this.chan.send_request(msgs, msgs.length, response, timeout, 0);
    }

    /**
    Sets the default timeout value for the channel.
    <p>
    @param timeout
    */
    public void setTimeout(long timeout) 
        throws DatabaseException {

        this.chan.set_timeout(timeout);
    }
}