/hazelcast/src/main/java/com/hazelcast/impl/management/MapConfigRequest.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 118 lines · 85 code · 18 blank · 15 comment · 12 complexity · 3acb117899d88be4017c42053e600a7e 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.management;
  17. import com.hazelcast.config.MapConfig;
  18. import com.hazelcast.nio.Address;
  19. import java.io.DataInput;
  20. import java.io.DataOutput;
  21. import java.io.IOException;
  22. public class MapConfigRequest implements ConsoleRequest {
  23. private String map;
  24. private MapConfig config;
  25. private boolean update;
  26. private Address target;
  27. public MapConfigRequest() {
  28. }
  29. public MapConfigRequest(String map, MapConfig config) {
  30. super();
  31. this.map = map;
  32. this.config = config;
  33. this.update = true;
  34. }
  35. public MapConfigRequest(String map, Address target) {
  36. super();
  37. this.map = map;
  38. this.target = target;
  39. this.update = false;
  40. }
  41. public Address getTarget() {
  42. return target;
  43. }
  44. public void setTarget(Address target) {
  45. this.target = target;
  46. }
  47. public int getType() {
  48. return ConsoleRequestConstants.REQUEST_TYPE_MAP_CONFIG;
  49. }
  50. public void writeResponse(ManagementCenterService mcs, DataOutput dos)
  51. throws Exception {
  52. dos.writeBoolean(update);
  53. if (update) {
  54. mcs.callOnAllMembers(new UpdateMapConfigCallable(map, config));
  55. dos.writeUTF("success");
  56. } else {
  57. MapConfig cfg = (MapConfig) mcs.call(target, new GetMapConfigCallable(map));
  58. if (cfg != null) {
  59. dos.writeBoolean(true);
  60. cfg.writeData(dos);
  61. } else {
  62. dos.writeBoolean(false);
  63. }
  64. }
  65. }
  66. public Object readResponse(DataInput in) throws IOException {
  67. update = in.readBoolean();
  68. if (!update) {
  69. if (in.readBoolean()) {
  70. MapConfig cfg = new MapConfig();
  71. cfg.readData(in);
  72. return cfg;
  73. }
  74. else {
  75. return null;
  76. }
  77. }
  78. return in.readUTF();
  79. }
  80. public void writeData(DataOutput out) throws IOException {
  81. out.writeUTF(map);
  82. out.writeBoolean(update);
  83. if (update) {
  84. config.writeData(out);
  85. } else {
  86. target.writeData(out);
  87. }
  88. }
  89. public void readData(DataInput in) throws IOException {
  90. map = in.readUTF();
  91. update = in.readBoolean();
  92. if (update) {
  93. config = new MapConfig();
  94. config.readData(in);
  95. } else {
  96. target = new Address();
  97. target.readData(in);
  98. }
  99. }
  100. }