001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 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 */
018package org.jppf.android.node;
019
020import android.util.Log;
021import android.view.View;
022import android.widget.LinearLayout;
023
024import org.jppf.node.event.NodeLifeCycleEvent;
025import org.jppf.node.event.TaskExecutionEvent;
026
027/**
028 * This is the default node events handler, used if none is provided by the jobs.
029 * @author Laurent Cohen
030 * @since 5.1
031 */
032public class SimpleNodeIntegration extends AndroidNodeIntegrationAdapter {
033  // Atomic counter for the number of tasks executed by the node.
034  private long totalTasks = 0L;
035  // The view displayed by this feedback handler.
036  private View view = null;
037
038  @Override public View getContentView() {
039    if ((view == null) && (getActivity() != null)) {
040      view = new LinearLayout(getActivity()); // return an empty layout
041    }
042    return view;
043  }
044
045  @Override public void taskExecuted(final TaskExecutionEvent event) {
046    Log.v("SimpleNodeIntegration", String.format("received event from task id '%s' : %s", event.getTask().getId(), event.getUserObject()));
047  }
048
049  @Override public void nodeStarting(final NodeLifeCycleEvent event) {
050    Log.v("SimpleNodeIntegration", "the node is connected!");
051  }
052
053  @Override public void nodeEnding(final NodeLifeCycleEvent event) {
054    Log.v("SimpleNodeIntegration", "the node is disconnected!");
055  }
056
057  @Override public void jobStarting(final NodeLifeCycleEvent event) {
058    Log.v("SimpleNodeIntegration", "starting job '" + event.getJob().getName() + "'");
059  }
060
061  @Override public void jobEnding(final NodeLifeCycleEvent event) {
062    Log.v("SimpleNodeIntegration", "ending job '" + event.getJob().getName() + "'");
063    Log.v("SimpleNodeIntegration", "total tasks exectued: " + (totalTasks += event.getTasks().size()));
064  }
065}