All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aol.micro.server.dist.lock.rest.DistLockResource Maven / Gradle / Ivy

package com.aol.micro.server.dist.lock.rest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aol.cyclops.data.collections.extensions.standard.ListX;
import com.aol.micro.server.auto.discovery.SingletonRestResource;
import com.aol.micro.server.dist.lock.DistributedLockManager;

@Component
@Path("/lock-owner")
public class DistLockResource implements SingletonRestResource {

    private final Map lockController;

    @Autowired(required = false)
    public DistLockResource(List lockController) {
        this.lockController = ListX.fromIterable(lockController)
                                   .toMap(lc -> lc.getKey(), lc -> lc);
    }

    public DistLockResource() {
        lockController = new HashMap<>();
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("{lockName}")
    public boolean ownLock(@PathParam("lockName") final String lockName) {
        if (!lockController.containsKey(lockName))
            return false;
        return lockController.get(lockName)
                             .isMainProcess();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy