PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/impl/MergeClusters.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 73 lines | 46 code | 12 blank | 15 comment | 5 complexity | 344ab99fefaf85571040113869c51443 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.impl;
18
19import com.hazelcast.cluster.AbstractRemotelyProcessable;
20import com.hazelcast.logging.ILogger;
21import com.hazelcast.nio.Address;
22
23import java.io.DataInput;
24import java.io.DataOutput;
25import java.io.IOException;
26import java.util.logging.Level;
27
28public class MergeClusters extends AbstractRemotelyProcessable {
29
30    private Address newTargetAddress = null;
31
32    public MergeClusters() {
33    }
34
35    public MergeClusters(Address newTargetAddress) {
36        super();
37        this.newTargetAddress = newTargetAddress;
38    }
39
40    public void process() {
41        if (conn == null) {
42            return;
43        }
44
45        final Address endpoint = conn.getEndPoint();
46        final Address masterAddress = node.getMasterAddress();
47        final ILogger logger = node.loggingService.getLogger(this.getClass().getName());
48        if (endpoint == null || !endpoint.equals(masterAddress)) {
49            logger.log(Level.WARNING, "Merge instruction sent from non-master endpoint: " + endpoint);
50            return;
51        }
52
53        node.getExecutorManager().executeNow(new Runnable() {
54            public void run() {
55                logger.log(Level.WARNING, node.address + " is merging to " + newTargetAddress
56                                          + ", because: instructed by master " + masterAddress);
57                node.getJoiner().setTargetAddress(newTargetAddress);
58                node.factory.restart();
59            }
60        });
61    }
62
63    public void readData(DataInput in) throws IOException {
64        super.readData(in);
65        newTargetAddress = new Address();
66        newTargetAddress.readData(in);
67    }
68
69    public void writeData(DataOutput out) throws IOException {
70        super.writeData(out);
71        newTargetAddress.writeData(out);
72    }
73}