/* * @see org.gamegineer.table.net.ITableNetwork#getPlayers() */ @Override public Collection<IPlayer> getPlayers() { final INodeController nodeController = nodeControllerRef_.get(); if (nodeController != null) { return nodeController.getPlayers(); } return new ArrayList<>(); }
/* * @see org.gamegineer.table.net.ITableNetwork#getLocalPlayer() */ @Override public @Nullable IPlayer getLocalPlayer() { final INodeController nodeController = nodeControllerRef_.get(); if (nodeController != null) { return nodeController.getPlayer(); } return null; }
/* * @see org.gamegineer.table.net.ITableNetwork#requestControl() */ @Override public void requestControl() { final INodeController nodeController = nodeControllerRef_.get(); if (nodeController != null) { final IPlayer nodeControllerPlayer = nodeController.getPlayer(); assert nodeControllerPlayer != null; ThreadPlayer.setPlayerName(nodeControllerPlayer.getName()); try { nodeController.requestControl(); } finally { ThreadPlayer.setPlayerName(null); } } }
/* * @see org.gamegineer.table.internal.net.impl.ITableNetworkController#disconnect(org.gamegineer.table.net.TableNetworkError) */ @Override public void disconnect(final @Nullable TableNetworkError error) throws InterruptedException { if (connectionStateRef_.compareAndSet( ConnectionState.CONNECTED, ConnectionState.DISCONNECTING)) { final INodeController nodeController = nodeControllerRef_.getAndSet(null); try { if (nodeController != null) { nodeController.endDisconnect(nodeController.beginDisconnect()); } } finally { connectionStateRef_.set(ConnectionState.DISCONNECTED); fireTableNetworkDisconnected(error); } } }
/** * Connects the specified table network node to the table network defined by the specified * configuration. * * @param configuration The table network configuration. * @param nodeController The control interface of the table network node. * @throws java.lang.InterruptedException If this thread is interrupted while waiting for the * table network to connect. * @throws org.gamegineer.table.net.TableNetworkException If the connection cannot be established * or the table network is already connected. */ private void connect( final TableNetworkConfiguration configuration, final INodeController nodeController) throws TableNetworkException, InterruptedException { if (connectionStateRef_.compareAndSet( ConnectionState.DISCONNECTED, ConnectionState.CONNECTING)) { try { nodeController.endConnect(nodeController.beginConnect(configuration)); nodeControllerRef_.set(nodeController); connectionStateRef_.set(ConnectionState.CONNECTED); fireTableNetworkConnected(); } catch (final TableNetworkException e) { connectionStateRef_.set(ConnectionState.DISCONNECTED); throw e; } catch (final InterruptedException e) { connectionStateRef_.set(ConnectionState.DISCONNECTED); throw e; } } else { throw new TableNetworkException(TableNetworkError.ILLEGAL_CONNECTION_STATE); } }