001/*
002 * JPPF.
003 * Copyright (C) 2005-2018 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.node;
020
021import org.jppf.JPPFUnsupportedOperationException;
022import org.jppf.classloader.AbstractJPPFClassLoader;
023import org.jppf.management.*;
024import org.jppf.node.event.LifeCycleEventHandler;
025import org.jppf.serialization.*;
026import org.jppf.utils.concurrent.ThreadSynchronization;
027
028/**
029 * Abstract implementation of the {@link Node} interface.
030 * @author Laurent Cohen
031 */
032public abstract class AbstractNode extends ThreadSynchronization implements NodeInternal {
033  /**
034   * Utility for deserialization and serialization.
035   * @exclude
036   */
037  protected SerializationHelper helper = null;
038  /**
039   * Utility for deserialization and serialization.
040   * @exclude
041   */
042  protected ObjectSerializer serializer = null;
043  /**
044   * Total number of tasks executed.
045   * @exclude
046   */
047  private int taskCount = 0;
048  /**
049   * Used to synchronize access to the task count.
050   */
051  private final Object taskCountLock = new Object();
052  /**
053   * This node's universal identifier.
054   * @exclude
055   */
056  protected String uuid = null;
057  /**
058   * This node's system information.
059   * @exclude
060   */
061  protected JPPFSystemInformation systemInformation = null;
062  /**
063   * Get the connection used by this node.
064   * @exclude
065   */
066  protected NodeConnection<?> nodeConnection = null;
067
068  /**
069   * {@inheritDoc}
070   * @exclude
071   */
072  @Override
073  public NodeConnection<?> getNodeConnection() {
074    return nodeConnection;
075  }
076
077  /**
078   * Get the total number of tasks executed.
079   * @return the number of tasks as an int.
080   */
081  public int getTaskCount() {
082    synchronized (taskCountLock) {
083      return taskCount;
084    }
085  }
086
087  /**
088   * Set the total number of tasks executed.
089   * @param taskCount the number of tasks as an int.
090   * @exclude
091   */
092  public void setTaskCount(final int taskCount) {
093    synchronized (taskCountLock) {
094      this.taskCount = taskCount;
095    }
096  }
097
098  /**
099   * Get the utility for deserialization and serialization.
100   * @return a <code>SerializationHelper</code> instance.
101   * @exclude
102   */
103  public SerializationHelper getHelper() {
104    return helper;
105  }
106
107  /**
108   * Default implementation
109   * @return this method always returns null.
110   * @see org.jppf.node.NodeInternal#getLifeCycleEventHandler()
111   * @exclude
112   */
113  @Override
114  public LifeCycleEventHandler getLifeCycleEventHandler() {
115    return null;
116  }
117
118  /**
119   * {@inheritDoc}
120   * <p>This implementation throws a <code>JPPFUnsupportedOperationException</code>. It is up to subclasses to implement it.
121   * @exclude
122   */
123  @Override
124  public JMXServer getJmxServer() throws Exception {
125    throw new JPPFUnsupportedOperationException("getJmxServer() is not supported on this type of node");
126  }
127
128  @Override
129  public String getUuid() {
130    return uuid;
131  }
132
133  /**
134   * Update the current system information.
135   * @exclude
136   */
137  protected void updateSystemInformation() {
138    this.systemInformation = new JPPFSystemInformation(uuid, isLocal(), true);
139  }
140
141  @Override
142  public JPPFSystemInformation getSystemInformation() {
143    return systemInformation;
144  }
145
146  /**
147   * This implementation does nothing.
148   * @param params not used.
149   * @return {@code null}.
150   * @exclude
151   */
152  @Override
153  public AbstractJPPFClassLoader resetTaskClassLoader(final Object...params) {
154    return null;
155  }
156
157  @Override
158  public boolean isAndroid() {
159    return false;
160  }
161}