| /*=============================================================================# |
| # Copyright (c) 2009, 2017 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.rj.servi.pool; |
| |
| import org.eclipse.statet.ecommons.rmi.core.RMIAddress; |
| |
| import org.eclipse.statet.internal.rj.servi.NodeHandler; |
| import org.eclipse.statet.rj.RjException; |
| |
| |
| public class PoolNodeItem { |
| |
| |
| private long creationTime; |
| |
| private PoolNodeState state; |
| private long stateTime; |
| |
| private long usageCount; |
| private long usageDuration; |
| |
| private final PoolNodeObject object; |
| private final NodeHandler nodeHandler; |
| |
| private String client; |
| |
| |
| public PoolNodeItem(final PoolNodeObject nodeObj, final long stamp) { |
| synchronized(nodeObj) { |
| this.object= nodeObj; |
| this.nodeHandler= nodeObj.getNodeHandler(); |
| |
| this.creationTime= nodeObj.getCreationTime(); |
| this.state= nodeObj.getState(); |
| |
| this.stateTime= nodeObj.getStateTime(); |
| this.usageCount= nodeObj.getAllocatedCount(); |
| this.usageDuration= nodeObj.getAllocatedDuration(); |
| // if (this.state == PoolNodeState.ALLOCATED) { |
| // this.usageDuration+= Math.min(stamp - this.stateTime, 0L); |
| // } |
| this.client= nodeObj.getClientLabel(); |
| } |
| } |
| |
| |
| public long getCreationTime() { |
| return this.creationTime; |
| } |
| |
| public PoolNodeState getState() { |
| return this.state; |
| } |
| |
| public long getStateTime() { |
| return this.stateTime; |
| } |
| |
| public String getCurrentClientId() { |
| return this.client; |
| } |
| |
| public long getUsageCount() { |
| return this.usageCount; |
| } |
| |
| public long getUsageDuration() { |
| return this.usageDuration; |
| } |
| |
| public boolean isConsoleEnabled() { |
| return (this.nodeHandler != null && this.nodeHandler.isConsoleEnabled()); |
| } |
| |
| public void enableConsole(final String authConfig) throws RjException { |
| if (this.nodeHandler != null) { |
| this.nodeHandler.enableConsole(authConfig); |
| } |
| } |
| |
| public void disableConsole() throws RjException { |
| if (this.nodeHandler != null) { |
| this.nodeHandler.disableConsole(); |
| } |
| } |
| |
| /** |
| * Returns the RMI address of the node. |
| * |
| * @return the address of the node if available, otherwise <code>null</code> |
| * |
| * @since 2.0 |
| */ |
| public RMIAddress getAddress() { |
| if (this.nodeHandler != null) { |
| return this.nodeHandler.getAddress(); |
| } |
| return null; |
| } |
| |
| /** |
| * Evicts the pool item. |
| * |
| * The specified timeout is used when the node is in use. |
| * |
| * @param timeoutMillis the timeout in milliseconds |
| * |
| * @since 2.0 |
| */ |
| public void evict(final long timeoutMillis) { |
| if (this.object != null) { |
| this.object.evict(timeoutMillis); |
| } |
| } |
| |
| } |