PageRenderTime 45ms CodeModel.GetById 41ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/cluster/Bind.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 74 lines | 47 code | 12 blank | 15 comment | 3 complexity | 95d32998caf8fdb9b2a9cd5ecec94b62 MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.cluster;
18
19import com.hazelcast.nio.Address;
20
21import java.io.DataInput;
22import java.io.DataOutput;
23import java.io.IOException;
24
25public class Bind extends Master {
26
27    private Address targetAddress;
28    private boolean replyBack = false;
29
30    public Bind() {
31    }
32
33    public Bind(Address localAddress) {
34        super(localAddress);
35        this.targetAddress = null;
36    }
37
38    public Bind(Address localAddress, final Address targetAddress, final boolean replyBack) {
39        super(localAddress);
40        this.targetAddress = targetAddress;
41        this.replyBack = replyBack;
42    }
43
44    public void process() {
45        getNode().connectionManager.bind(getConnection(), address, targetAddress, replyBack);
46    }
47
48    @Override
49    public void readData(final DataInput in) throws IOException {
50        super.readData(in);
51        boolean hasTarget = in.readBoolean();
52        if (hasTarget) {
53            targetAddress = new Address();
54            targetAddress.readData(in);
55        }
56        replyBack = in.readBoolean();
57    }
58
59    @Override
60    public void writeData(final DataOutput out) throws IOException {
61        super.writeData(out);
62        boolean hasTarget = targetAddress != null;
63        out.writeBoolean(hasTarget);
64        if (hasTarget) {
65            targetAddress.writeData(out);
66        }
67        out.writeBoolean(replyBack);
68    }
69
70    @Override
71    public String toString() {
72        return "Bind " + address;
73    }
74}