/*
 * Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.cp.internal.datastructures.spi.client;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.codec.CPGroupCreateCPGroupCodec;
import com.hazelcast.client.impl.protocol.task.AbstractMessageTask;
import com.hazelcast.cp.internal.RaftGroupId;
import com.hazelcast.cp.internal.RaftService;
import com.hazelcast.instance.Node;
import com.hazelcast.nio.Connection;

import java.security.Permission;

/**
 * Client message task for Raft group creation
 */
public class CreateRaftGroupMessageTask extends AbstractMessageTask<CPGroupCreateCPGroupCodec.RequestParameters> {

    public CreateRaftGroupMessageTask(ClientMessage clientMessage, Node node, Connection connection) {
        super(clientMessage, node, connection);
    }

    @Override
    protected void processMessage() {
        RaftService service = nodeEngine.getService(RaftService.SERVICE_NAME);
        RaftGroupId groupId = service.createRaftGroupForProxy(parameters.proxyName);
        sendResponse(groupId);
    }

    @Override
    protected CPGroupCreateCPGroupCodec.RequestParameters decodeClientMessage(ClientMessage clientMessage) {
        return CPGroupCreateCPGroupCodec.decodeRequest(clientMessage);
    }

    @Override
    protected ClientMessage encodeResponse(Object response) {
        return CPGroupCreateCPGroupCodec.encodeResponse((RaftGroupId) response);
    }

    @Override
    public String getServiceName() {
        return RaftService.SERVICE_NAME;
    }

    @Override
    public String getDistributedObjectName() {
        return parameters.proxyName;
    }

    @Override
    public Permission getRequiredPermission() {
        return null;
    }

    @Override
    public String getMethodName() {
        return "createRaftGroup";
    }

    @Override
    public Object[] getParameters() {
        return new Object[] {parameters.proxyName};
    }
}

@@ -882,16 +882,84 @@
 geTask;%0A
+import com.hazelcast.client.impl.protocol.task.BlockingMessageTask;%0A
 import c
@@ -1317,16 +1317,55 @@
 ameters%3E
+%0A        implements BlockingMessageTask
  %7B%0A%0A    
@@ -2601,17 +2601,16 @@
 Object%5B%5D
- 
 %7Bparamet

mark CreateRaftGroupMessageTask as BlockingMessageTask since it waits for remote response