summaryrefslogtreecommitdiff
path: root/Java-Kompendium/kap20/2/src/main/java/Server.java
blob: 14c013a69acdc0bd21969cb22d8d7b7970dc8c56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class Server extends Thread {
    public final Semaphore lock = new Semaphore(1);

    public Server() throws InterruptedException {
        this.lock.acquire();
    }

    @Override
    public void run() {
        try {
            RMIInterface server = new RMIKlasse();
            RMIInterface stub = (RMIInterface) UnicastRemoteObject.exportObject((RMIInterface) server, 0);
            Registry registrierung = LocateRegistry.createRegistry(1099);
            registrierung.rebind("RMIAufgabe", stub);
        } catch (RemoteException e) {
            System.out.println("Server: ");
            System.out.println(e);
        } finally {
            this.lock.release();
        }
    }
}