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