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

hu.akarnokd.reactiverpc.RpcStreamContextImpl Maven / Gradle / Ivy

package hu.akarnokd.reactiverpc;

import java.net.InetAddress;
import java.util.concurrent.*;

import rsc.scheduler.Scheduler;

final class RpcStreamContextImpl implements RpcStreamContext {
    
    final InetAddress address;
    
    final int port;
    
    final ConcurrentMap map;
    
    final T remoteAPI;
    
    final Scheduler scheduler;
    
    public RpcStreamContextImpl(InetAddress address, int port, T remoteAPI, Scheduler scheduler) {
        this.address = address;
        this.port = port;
        this.remoteAPI = remoteAPI;
        this.scheduler = scheduler;
        this.map = new ConcurrentHashMap<>();
    }

    @Override
    public InetAddress clientAddress() {
        return address;
    }

    @Override
    public int clientPort() {
        return port;
    }

    @Override
    public void set(String attribute, Object o) {
        map.put(attribute, o);
    }

    @SuppressWarnings("unchecked")
    @Override
    public  U get(String attribute) {
        return (U)map.get(attribute);
    }

    @SuppressWarnings("unchecked")
    @Override
    public  U get(String attribute, U defaultValue) {
        return (U)map.getOrDefault(attribute, defaultValue);
    }

    @Override
    public void remove(String attribute) {
        map.remove(attribute);
    }

    @Override
    public boolean has(String attribute) {
        return map.containsKey(attribute);
    }

    @Override
    public T remoteAPI() {
        return remoteAPI;
    }
    
    @Override
    public Scheduler scheduler() {
        return scheduler;
    }
}