| /******************************************************************************* |
| * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro |
| * 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: |
| * Gabor Bergmann - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.gtasm.patternmatcher.incremental; |
| |
| import java.util.Map; |
| import java.util.WeakHashMap; |
| |
| import org.eclipse.viatra2.framework.FrameworkManager; |
| import org.eclipse.viatra2.framework.IFramework; |
| import org.eclipse.viatra2.framework.IFrameworkListChangedListener; |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.adapters.MachineListener; |
| import org.eclipse.viatra2.gtasm.patternmatcher.incremental.rete.matcher.ReteEngine; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.gt.GTPattern; |
| |
| |
| |
| /** |
| * @author Gabor Bergmann |
| * |
| */ |
| public class EngineManager implements IFrameworkListChangedListener { |
| |
| private static EngineManager instance = new EngineManager(); |
| |
| /** |
| * @return the instance |
| */ |
| public static EngineManager getInstance() { |
| return instance; |
| } |
| |
| // Map<IFramework, ReteEngine> engines = new HashMap<IFramework, |
| // ReteEngine>(); |
| Map<IFramework, MachineListener> machineListeners; |
| |
| public EngineManager() { |
| super(); |
| this.machineListeners = new WeakHashMap<IFramework, MachineListener>(); |
| FrameworkManager.getInstance().addFrameworkListChangedListener(this); |
| } |
| |
| public ReteEngine<GTPattern> getReteEngine(IFramework framework) { |
| // ReteEngine engine = engines.get(framework); |
| // if (engine==null) |
| // { |
| // engine = new ReteEngine(framework); |
| // engines.put(framework, engine); |
| // } |
| |
| return getMachineListener(framework).getEngine(); |
| } |
| |
| public MachineListener getMachineListener(IFramework framework) { |
| MachineListener l = machineListeners.get(framework); |
| if (l == null) { |
| l = new MachineListener(framework); |
| machineListeners.put(framework, l); |
| } |
| return l; |
| } |
| |
| public void frameworkAdded(IFramework f) { |
| |
| } |
| |
| public void frameworkRemoved(IFramework f) { |
| MachineListener m = machineListeners.get(f); |
| if (m != null) |
| m.kill(); |
| machineListeners.remove(f); |
| } |
| |
| // private int threads(GTPattern samplePattern) { |
| // Machine machine = samplePattern.getNamespace(); |
| // machine.g |
| // return 0; |
| // } |
| |
| } |