Make SshScope accessors on a Singleton object.
SshScope used static methods to set the context, but the next change will require the ThreadLocalRequestContext to be injected in order to set the request scope. SshScope was updated to be a Singleton injected into the required objects. Change-Id: I20d4a7253edfa06f85af95e27980e4d6b4d160e2
This commit is contained in:
@@ -58,6 +58,7 @@ class NoShell implements Factory<Command> {
|
||||
|
||||
static class SendMessage implements Command, SessionAware {
|
||||
private final Provider<MessageFactory> messageFactory;
|
||||
private final SshScope sshScope;
|
||||
|
||||
private InputStream in;
|
||||
private OutputStream out;
|
||||
@@ -66,8 +67,9 @@ class NoShell implements Factory<Command> {
|
||||
private Context context;
|
||||
|
||||
@Inject
|
||||
SendMessage(Provider<MessageFactory> messageFactory) {
|
||||
SendMessage(Provider<MessageFactory> messageFactory, SshScope sshScope) {
|
||||
this.messageFactory = messageFactory;
|
||||
this.sshScope = sshScope;
|
||||
}
|
||||
|
||||
public void setInputStream(final InputStream in) {
|
||||
@@ -91,12 +93,12 @@ class NoShell implements Factory<Command> {
|
||||
}
|
||||
|
||||
public void start(final Environment env) throws IOException {
|
||||
Context old = SshScope.set(context);
|
||||
Context old = sshScope.set(context);
|
||||
String message;
|
||||
try {
|
||||
message = messageFactory.get().getMessage();
|
||||
} finally {
|
||||
SshScope.set(old);
|
||||
sshScope.set(old);
|
||||
}
|
||||
err.write(Constants.encode(message.toString()));
|
||||
err.flush();
|
||||
|
||||
Reference in New Issue
Block a user