| /******************************************************************************* |
| * Copyright (c) 2020 Aston University. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * This Source Code may also be made available under the following Secondary |
| * Licenses when the conditions for such availability set forth in the Eclipse |
| * Public License, v. 2.0 are satisfied: GNU General Public License, version 3. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR GPL-3.0 |
| * |
| * Contributors: |
| * Antonio Garcia-Dominguez - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.hawk.timeaware.graph; |
| |
| import java.lang.ref.WeakReference; |
| |
| import org.eclipse.hawk.core.graph.IGraphNode; |
| import org.eclipse.hawk.core.graph.timeaware.ITimeAwareGraphNode; |
| import org.eclipse.hawk.epsilon.emc.wrappers.GraphNodeWrapper; |
| import org.eclipse.hawk.timeaware.queries.TimeAwareEOLQueryEngine; |
| |
| /** |
| * Wraps a standalone node while remembering its original time, so we can |
| * retrieve the exact same node later if the weak reference has been GC'ed. |
| */ |
| public class TimeAwareGraphNodeWrapper extends GraphNodeWrapper { |
| |
| private long time; |
| |
| public TimeAwareGraphNodeWrapper(IGraphNode n, TimeAwareEOLQueryEngine containerModel) { |
| super(n, containerModel); |
| this.time = ((ITimeAwareGraphNode) n).getTime(); |
| } |
| |
| @Override |
| public IGraphNode getNode() { |
| IGraphNode ret = node.get(); |
| if (ret == null) { |
| TimeAwareEOLQueryEngine taQuery = (TimeAwareEOLQueryEngine)containerModel; |
| ret = taQuery.getBackend().getNodeById(id).travelInTime(time); |
| node = new WeakReference<IGraphNode>(ret); |
| } |
| return ret; |
| } |
| |
| |
| } |