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

remote.server.RemoteImpl Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package remote.server;

import java.io.ObjectStreamException;
import java.io.Serializable;
import java.rmi.RemoteException;

import remote.Function;
import remote.Remote;

public class RemoteImpl extends RemoteObject implements Remote, Serializable {
	private final RemoteFactory factory;
	private final T value;

	RemoteImpl(final T value, final RemoteFactory factory, final long num) {
		super(num);
		this.factory = factory;
		this.value = value;
	}

	@Override
	public  Remote map(Function f) throws RemoteException {
		return factory.apply(f.apply(value));
	}

	@Override
	public  Remote flatMap(Function> f) throws RemoteException {
		return f.apply(value);
	}

	@Override
	public T get() {
		return value;
	}

	private Object writeReplace() throws ObjectStreamException {
		return new RemoteImpl_Stub<>(factory.getId(), getNum(), factory);
	}
}