class PceccSrTeBeHandler {

    public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId) {
        long applyNum = 1; // For each node only one node label
        LabelResourceId specificLabelId = null;

        checkNotNull(specificDeviceId, DEVICE_ID_NULL);
        checkNotNull(specificLsrId, LSR_ID_NULL);
        checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
        checkNotNull(pceStore, PCE_STORE_NULL);

        // Check whether node-label was already configured for this specific device.
        if (pceStore.getGlobalNodeLabel(specificDeviceId) != null) {
            log.debug("Node label was already configured for device {}.", specificDeviceId.toString());
            return false;
        }

        // The specificDeviceId is the new device and is not there in the pce store.
        // So, first generate its label and configure label and its lsr-id to it.
        Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum);
        if (result.size() > 0) {
            // Only one element (label-id) to retrieve
            Iterator<LabelResource> iterator = result.iterator();
            DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next();
            specificLabelId = defaultLabelResource.labelResourceId();
            if (specificLabelId == null) {
                log.error("Unable to retrieve global node label for a device id {}.", specificDeviceId.toString());
                return false;
            }
        } else {
            log.error("Unable to allocate global node label for a device id {}.", specificDeviceId.toString());
            return false;
        }

        // store it
        pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId);

        // Push its label information into specificDeviceId
        advertiseNodeLabelRule(specificDeviceId, specificLabelId,
                               IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
                               Objective.Operation.ADD, false);

        // Configure (node-label, lsr-id) mapping of each devices into specific device and vice versa.
        for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) {
            DeviceId otherDevId = element.getKey();
            LabelResourceId otherLabelId = element.getValue();

            // Get lsr-id of a device
            String otherLsrId = getLsrId(otherDevId);
            if (otherLsrId == null) {
                log.error("The lsr-id of device id {} is null.", otherDevId.toString());
                releaseNodeLabel(specificDeviceId, specificLsrId);
                return false;
            }

            // Push to device
            // Push label information of specificDeviceId to otherDevId in list and vice versa.
            if (!otherDevId.equals(specificDeviceId)) {
                advertiseNodeLabelRule(otherDevId, specificLabelId,
                                       IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
                                       Objective.Operation.ADD, false);

                advertiseNodeLabelRule(specificDeviceId, otherLabelId,
                                       IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH),
                                       Objective.Operation.ADD, false);
            }
        }

        return true;
    }

    private  PceccSrTeBeHandler();

}