class PartitionedRegionIDGeneratorFunction implements Function, Declarable {

    @Override
    public void execute(FunctionContext functionContext) {
        try {
            String domain = null;
            Object arguments = functionContext.getArguments();

            if (arguments != null) {
                if (arguments.getClass().isArray()) {
                    Object[] args = (Object[]) arguments;
                    assert args.length == 1;
                    domain = args[0].toString();
                } else {
                    domain = arguments.toString();
                }
            } else {
                RegionFunctionContext rctx = (RegionFunctionContext) functionContext;
                Set<String> filter = (Set<String>) rctx.getFilter();
                assert filter.size() == 1;
                domain = filter.iterator().next();
            }

            LOG.debug("execute: domain={}", domain);
            Region<String, Long> region = getRegion();

            synchronized (PartitionedRegionIDGeneratorFunction.class) {
                Long firstId = region.computeIfAbsent(domain, t -> -1L) + 1;
                long lastId = firstId + idCount - 1;
                LOG.debug("execute: domain={}, firstId={}, lastId={}", domain, firstId, lastId);
                region.put(domain, lastId);
                functionContext.getResultSender().lastResult(new long[]{firstId, lastId});
            }
        } catch (Exception x) {
            LOG.error("execute: x={}", x.toString(), x);
            throw new IllegalArgumentException(x.toString(), x);
        }
    }

    public  PartitionedRegionIDGeneratorFunction();
    public  PartitionedRegionIDGeneratorFunction(String idRegionName, int idCount);
    public  PartitionedRegionIDGeneratorFunction(int idCount, Region<String, Long> idRegion);

}