Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/RunConsole.java93
1 files changed, 67 insertions, 26 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/RunConsole.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/RunConsole.java
index 33e7fa9424..36f9b88c3f 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/RunConsole.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/RunConsole.java
@@ -43,8 +43,11 @@ public class RunConsole extends IOConsole {
/** Id of this console. */
public static final String ID = "containerLog"; //$NON-NLS-1$
public static final String CONTAINER_LOG_TITLE = "ContainerLog.title"; //$NON-NLS-1$
+ public static final String DEFAULT_ID = "__DEFAULT_ID__"; //$NON-NLS-1$
private String containerId;
+ private String id;
+
private OutputStream outputStream;
private boolean attached = false;
private final WritableByteChannel[] ptyOutRef = new WritableByteChannel[1];
@@ -53,17 +56,48 @@ public class RunConsole extends IOConsole {
* Returns a reference to the console that is for the given container id. If
* such a console does not yet exist, it will be created.
*
+ * @param containerId
+ * The container id this console will be for. Must not be
+ * <code>null</code>.
+ * @return A console instance or <code>null</code> if the given containerId
+ * was <code>null</code>.
+ */
+ public static RunConsole findConsole(String containerId) {
+ if (containerId == null)
+ return null;
+ return findConsole(containerId, DEFAULT_ID);
+ }
+
+ /**
+ * Returns a reference to the console that is for the given container id. If
+ * such a console does not yet exist, it will be created.
+ *
* @param container
- * The container this console will be for. Should not be
+ * The container this console will be for. Must not be
* <code>null</code>.
- * @return A console instance or <code>null</code> if the given container
+ * @return A console instance or <code>null</code> if the given containerId
* was <code>null</code>.
*/
- public static RunConsole findConsole(final IDockerContainer container) {
- if (container == null) {
+ public static RunConsole findConsole(IDockerContainer container) {
+ if (container == null)
return null;
- }
- return findConsole(container.id(), container.name());
+ return findConsole(container.id(), DEFAULT_ID);
+ }
+
+ /**
+ * Returns a reference to the console that is for the given container id. If
+ * such a console does not yet exist, it will be created.
+ *
+ * @param containerId
+ * The container this console will be for. Must not be
+ * <code>null</code>.
+ * @param id
+ * The secondary id used to identify consoles belonging to
+ * various owners.
+ * @return A console instance.
+ */
+ public static RunConsole findConsole(String containerId, String id) {
+ return findConsole(containerId, id, containerId.substring(0, 8));
}
/**
@@ -80,20 +114,25 @@ public class RunConsole extends IOConsole {
* the name of the console to create if it did not already exist
* @return A console instance.
*/
- public static RunConsole findConsole(final String containerId,
- final String name) {
+ public static RunConsole findConsole(String containerId, String id,
+ String name) {
+ RunConsole ret = null;
for (IConsole cons : ConsolePlugin.getDefault().getConsoleManager()
.getConsoles()) {
if (cons instanceof RunConsole
- && ((RunConsole) cons).containerId.equals(containerId)) {
- return (RunConsole) cons;
+ && ((RunConsole) cons).containerId.equals(containerId)
+ && ((RunConsole) cons).id.equals(id)) {
+ ret = (RunConsole) cons;
}
}
// no existing console, create new one
- final RunConsole console = new RunConsole(containerId, name);
- ConsolePlugin.getDefault().getConsoleManager()
- .addConsoles(new IConsole[] { console });
- return console;
+ if (ret == null) {
+ ret = new RunConsole(containerId, id, name);
+ ConsolePlugin.getDefault().getConsoleManager()
+ .addConsoles(new IConsole[] { ret });
+ }
+
+ return ret;
}
@Override
@@ -125,13 +164,14 @@ public class RunConsole extends IOConsole {
public void run() {
try {
DockerConnection conn = (DockerConnection) connection;
- if (conn.getContainerInfo(containerId).config().openStdin()) {
+ if (conn.getContainerInfo(containerId).config()
+ .openStdin()) {
while (!conn.getContainerInfo(containerId).state()
.running()) {
Thread.sleep(1000);
}
- WritableByteChannel pty_out = conn.attachCommand(
- containerId, in, out);
+ WritableByteChannel pty_out = conn
+ .attachCommand(containerId, in, out);
if (conn.getContainerInfo(containerId).config().tty()) {
ptyOutRef[0] = pty_out;
}
@@ -217,10 +257,11 @@ public class RunConsole extends IOConsole {
* @param name
* The name to use for the console.
*/
- private RunConsole(String containerId, String name) {
+ private RunConsole(String containerId, String id, String name) {
super(DVMessages.getFormattedString(CONTAINER_LOG_TITLE, name), ID,
null, true);
this.containerId = containerId;
+ this.id = id;
}
/*
@@ -268,8 +309,8 @@ public class RunConsole extends IOConsole {
isCtrlOn = false;
break;
case TAB_CODE:
- pty_out.write(ByteBuffer
- .wrap(new byte[] { 9, 9 }, 0, 2));
+ pty_out.write(
+ ByteBuffer.wrap(new byte[] { 9, 9 }, 0, 2));
break;
}
} catch (IOException e1) {
@@ -283,16 +324,16 @@ public class RunConsole extends IOConsole {
WritableByteChannel pty_out = ptyOutRef[0];
try {
switch (e.keyCode) {
- /*
- * TODO : These values are configurable, so we should start
- * using 'stty -a' to know what they really are.
- */
+ /*
+ * TODO : These values are configurable, so we should
+ * start using 'stty -a' to know what they really are.
+ */
case C_CODE:
// ETX (End Of Text) (3) is usually the interrupt
// signal.
if (isCtrlOn) {
- pty_out.write(ByteBuffer.wrap(new byte[] { 3 }, 0,
- 1));
+ pty_out.write(
+ ByteBuffer.wrap(new byte[] { 3 }, 0, 1));
}
break;
case CTRL_CODE:

Back to the top