PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

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