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

io.molr.commons.domain.AtomicIncrementMissionHandleFactory Maven / Gradle / Ivy

/**
 * Copyright (c) 2018 European Organisation for Nuclear Research (CERN), All Rights Reserved.
 */

package io.molr.commons.domain;

import java.util.concurrent.atomic.AtomicLong;

public class AtomicIncrementMissionHandleFactory implements MissionHandleFactory {

    private final AtomicLong nextId;
    private final Object target;

    public AtomicIncrementMissionHandleFactory(Object target) {
        this.target = target;
        nextId = new AtomicLong(0);
    }

    @Override
    public MissionHandle createHandle() {
        String className = target.getClass().getName();
        String hashCode = "" + System.identityHashCode(target);
        String nextId = "" + this.nextId.getAndIncrement();
        return MissionHandle.ofId(String.format("%s::%s::%s", className, hashCode, nextId));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy