Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 67df36f8594c323328a5111e03515252104f3de0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*******************************************************************************
 * Copyright (c) 2011, 2017 SAP AG
 * 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:
 *     Lazar Kirchev, SAP AG - initial API and implementation
 *******************************************************************************/

package org.eclipse.equinox.console.ssh;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.felix.service.command.CommandProcessor;
import org.apache.sshd.common.Factory;
import org.apache.sshd.server.Command;
import org.osgi.framework.BundleContext;

/**
 *  Shell factory used by the SSH server to create a SSH shell
 *
 */
public class SshShellFactory implements Factory<Command> {
	
	private List<CommandProcessor> processors;
	private BundleContext context;
	private Set<SshShell> shells = new HashSet<>();
	
	public SshShellFactory(List<CommandProcessor> processors, BundleContext context) {
		this.processors = processors;
		this.context = context;
	}
	
	@Override
	public synchronized Command create() {
		SshShell shell = new SshShell(processors, context);
		shells.add(shell);
		return shell;
	}
	
	public synchronized void addCommandProcessor (CommandProcessor processor) {
		processors.add(processor);
		for (SshShell shell : shells) {
			shell.addCommandProcessor(processor);
		}
	}
	
	public synchronized void removeCommandProcessor (CommandProcessor processor) {
		processors.remove(processor);
		for (SshShell shell : shells) {
			shell.removeCommandProcessor(processor);
		}
	}
	
	public void exit() {
		for(SshShell shell : shells) {
			shell.onExit();
		}
	}
}

Back to the top