/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. package com.hazelcast.cluster;
  17. import com.hazelcast.nio.Address;
  18. import java.io.DataInput;
  19. import java.io.DataOutput;
  20. import java.io.IOException;
  21. public class Bind extends Master {
  22. private Address targetAddress;
  23. private boolean replyBack = false;
  24. public Bind() {
  25. }
  26. public Bind(Address localAddress) {
  27. super(localAddress);
  28. this.targetAddress = null;
  29. }
  30. public Bind(Address localAddress, final Address targetAddress, final boolean replyBack) {
  31. super(localAddress);
  32. this.targetAddress = targetAddress;
  33. this.replyBack = replyBack;
  34. }
  35. public void process() {
  36. getNode().connectionManager.bind(getConnection(), address, targetAddress, replyBack);
  37. }
  38. @Override
  39. public void readData(final DataInput in) throws IOException {
  40. super.readData(in);
  41. boolean hasTarget = in.readBoolean();
  42. if (hasTarget) {
  43. targetAddress = new Address();
  44. targetAddress.readData(in);
  45. }
  46. replyBack = in.readBoolean();
  47. }
  48. @Override
  49. public void writeData(final DataOutput out) throws IOException {
  50. super.writeData(out);
  51. boolean hasTarget = targetAddress != null;
  52. out.writeBoolean(hasTarget);
  53. if (hasTarget) {
  54. targetAddress.writeData(out);
  55. }
  56. out.writeBoolean(replyBack);
  57. }
  58. @Override
  59. public String toString() {
  60. return "Bind " + address;
  61. }
  62. }