/******************************************************************************* * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved. * This program and the accompanying materials are made available under the terms * of the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ package org.eclipse.tcf.te.tcf.core.internal.channelmanager.steps; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.runtime.stepper.StepperAttributeUtil; import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; import org.eclipse.tcf.te.tcf.core.interfaces.steps.ITcfStepAttributes; import org.eclipse.tcf.te.tcf.core.steps.AbstractPeerStep; /** * Calculate the log name to use for logging the backend communication. */ public class CalculateLogNameStep extends AbstractPeerStep { /* (non-Javadoc) * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#validateExecute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor) */ @Override public void validateExecute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor) throws CoreException { Assert.isNotNull(context); Assert.isNotNull(data); Assert.isNotNull(fullQualifiedId); Assert.isNotNull(monitor); } /* (non-Javadoc) * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#execute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) */ @Override public void execute(final IStepContext context, final IPropertiesContainer data, final IFullQualifiedId fullQualifiedId, final IProgressMonitor monitor, final ICallback callback) { Assert.isNotNull(context); Assert.isNotNull(data); Assert.isNotNull(fullQualifiedId); Assert.isNotNull(monitor); Assert.isNotNull(callback); final IPeer peer = getActivePeerContext(context, data, fullQualifiedId); Assert.isNotNull(peer); Runnable runnable = new Runnable() { @Override public void run() { // Get the peer name String logname = peer.getName(); if (logname != null) { // Get the peer host IP address String ip = peer.getAttributes().get(IPeer.ATTR_IP_HOST); // Fallback: The peer id if (ip == null || "".equals(ip.trim())) { //$NON-NLS-1$ ip = peer.getID(); } // Append the peer host IP address if (ip != null && !"".equals(ip.trim())) { //$NON-NLS-1$ logname += " " + ip.trim(); //$NON-NLS-1$ } // Write to the data store StepperAttributeUtil.setProperty(ITcfStepAttributes.ATTR_LOG_NAME, fullQualifiedId, data, logname, true); } callback(data, fullQualifiedId, callback, Status.OK_STATUS, null); } }; if (Protocol.isDispatchThread()) runnable.run(); else Protocol.invokeLater(runnable); } }