Search in sources :

Example 1 with DataOperation

use of com.alibaba.nacos.consistency.DataOperation in project nacos by alibaba.

the class PersistentClientOperationServiceImpl method onApply.

@Override
public Response onApply(WriteRequest request) {
    final InstanceStoreRequest instanceRequest = serializer.deserialize(request.getData().toByteArray());
    final DataOperation operation = DataOperation.valueOf(request.getOperation());
    final Lock lock = readLock;
    lock.lock();
    try {
        switch(operation) {
            case ADD:
                onInstanceRegister(instanceRequest.service, instanceRequest.instance, instanceRequest.getClientId());
                break;
            case DELETE:
                onInstanceDeregister(instanceRequest.service, instanceRequest.getClientId());
                break;
            default:
                return Response.newBuilder().setSuccess(false).setErrMsg("unsupport operation : " + operation).build();
        }
        return Response.newBuilder().setSuccess(true).build();
    } finally {
        lock.unlock();
    }
}
Also used : DataOperation(com.alibaba.nacos.consistency.DataOperation) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 2 with DataOperation

use of com.alibaba.nacos.consistency.DataOperation in project nacos by alibaba.

the class DistroDataRequestTest method testGetterAndSetter.

@Test
public void testGetterAndSetter() {
    DistroData distroData = mock(DistroData.class);
    DataOperation dataOperation = mock(DataOperation.class);
    DistroDataRequest req = new DistroDataRequest();
    req.setDistroData(distroData);
    req.setDataOperation(dataOperation);
    assertEquals(distroData, req.getDistroData());
    assertEquals(dataOperation, req.getDataOperation());
}
Also used : DataOperation(com.alibaba.nacos.consistency.DataOperation) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData) Test(org.junit.Test)

Aggregations

DataOperation (com.alibaba.nacos.consistency.DataOperation)2 DistroData (com.alibaba.nacos.core.distributed.distro.entity.DistroData)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Test (org.junit.Test)1