org.eclipse.wst.jsdt.debug.transport_1.0.1.v201201112313

16:49:11.273 INFO  jd.cli.Main - Decompiling org.eclipse.wst.jsdt.debug.transport_1.0.1.v201201112313.jar
package org.eclipse.wst.jsdt.debug.transport;

import java.io.IOException;
import org.eclipse.wst.jsdt.debug.transport.packet.Packet;

public abstract interface Connection
{
  public abstract boolean isOpen();
  
  public abstract void close()
    throws IOException;
  
  public abstract void writePacket(Packet paramPacket)
    throws IOException;
  
  public abstract Packet readPacket()
    throws IOException;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.Connection
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport;

public abstract interface Constants
{
  public static final String COLON = ":";
  public static final String LOCALHOST = "localhost";
  public static final String LOCALHOST_IP = "127.0.0.1";
  public static final String PORT = "port";
  public static final String UTF_8 = "UTF-8";
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.Constants
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport;

import org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException;
import org.eclipse.wst.jsdt.debug.transport.exception.TimeoutException;
import org.eclipse.wst.jsdt.debug.transport.packet.Packet;
import org.eclipse.wst.jsdt.debug.transport.packet.PacketReceiveManager;
import org.eclipse.wst.jsdt.debug.transport.packet.PacketSendManager;
import org.eclipse.wst.jsdt.debug.transport.packet.Response;

public class DebugSession
{
  private final PacketReceiveManager packetReceiveManager;
  private final PacketSendManager packetSendManager;
  
  public DebugSession(Connection connection)
  {
    packetReceiveManager = new PacketReceiveManager(connection);
    Thread receiveThread = new Thread(packetReceiveManager, "Debug Session - Receive Manager");
    receiveThread.setDaemon(true);
    
    packetSendManager = new PacketSendManager(connection);
    Thread sendThread = new Thread(packetSendManager, "Debug Session - Send Manager");
    sendThread.setDaemon(true);
    
    packetReceiveManager.setPartnerThread(sendThread);
    packetSendManager.setPartnerThread(receiveThread);
    
    receiveThread.start();
    sendThread.start();
  }
  
  public void dispose()
  {
    packetReceiveManager.disconnect();
    packetSendManager.disconnect();
  }
  
  public void send(Packet packet)
    throws DisconnectedException
  {
    if (packet == null) {
      throw new IllegalArgumentException("You cannot send a null request");
    }
    packetSendManager.sendPacket(packet);
  }
  
  public Response receiveResponse(int requestSequence, int timeout)
    throws TimeoutException, DisconnectedException
  {
    return packetReceiveManager.getResponse(requestSequence, timeout);
  }
  
  public Packet receive(String type, int timeout)
    throws TimeoutException, DisconnectedException
  {
    return packetReceiveManager.getCommand(type, timeout);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.DebugSession
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport;

public abstract interface ListenerKey
{
  public abstract String address();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.ListenerKey
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport;

import java.io.IOException;

public abstract interface TransportService
{
  public abstract ListenerKey startListening(String paramString)
    throws IOException;
  
  public abstract void stopListening(ListenerKey paramListenerKey)
    throws IOException;
  
  public abstract Connection accept(ListenerKey paramListenerKey, long paramLong1, long paramLong2)
    throws IOException;
  
  public abstract Connection attach(String paramString, long paramLong1, long paramLong2)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.TransportService
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.exception;

public final class DisconnectedException
  extends Exception
{
  private static final long serialVersionUID = 3233213787459625769L;
  
  public DisconnectedException(String message, Exception exception)
  {
    super(message, exception);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.exception;

public final class TimeoutException
  extends Exception
{
  private static final long serialVersionUID = 1L;
  
  public TimeoutException(String message)
  {
    super(message);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.exception.TimeoutException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.packet;

import java.util.Map;

public abstract interface Event
  extends Packet
{
  public abstract String getEvent();
  
  public abstract Map getBody();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.packet.Event
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.packet;

import java.util.Map;

public abstract interface Packet
{
  public abstract String getType();
  
  public abstract Map toJSON();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.packet.Packet
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.packet;

import java.io.IOException;
import org.eclipse.wst.jsdt.debug.transport.Connection;

public abstract class PacketManager
  implements Runnable
{
  private final Connection connection;
  private volatile Thread partnerThread;
  private volatile IOException disconnectedException;
  
  protected PacketManager(Connection connection)
  {
    if (connection == null) {
      throw new IllegalArgumentException("You cannot create a new PacketManager with a null Connection");
    }
    this.connection = connection;
  }
  
  public Connection getConnection()
  {
    return connection;
  }
  
  public void disconnect(IOException exception)
  {
    disconnectedException = exception;
    disconnect();
  }
  
  public void disconnect()
  {
    try
    {
      connection.close();
    }
    catch (IOException e)
    {
      disconnectedException = e;
    }
    if (partnerThread != null) {
      partnerThread.interrupt();
    }
  }
  
  public boolean isDisconnected()
  {
    return (connection == null) || (!connection.isOpen());
  }
  
  public IOException getDisconnectedException()
  {
    return disconnectedException;
  }
  
  public void setPartnerThread(Thread thread)
  {
    if (thread == null) {
      throw new IllegalArgumentException("You cannot send a null partner thread on the PacketManager");
    }
    partnerThread = thread;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.packet.PacketManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.packet;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import org.eclipse.wst.jsdt.debug.transport.Connection;
import org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException;
import org.eclipse.wst.jsdt.debug.transport.exception.TimeoutException;

public final class PacketReceiveManager
  extends PacketManager
{
  public static final int TIMEOUT_NOT_BLOCKING = 0;
  public static final int TIMEOUT_INFINITE = -1;
  private List commandPackets = new LinkedList();
  private List responsePackets = new LinkedList();
  private List timedOutPackets = new ArrayList();
  
  public PacketReceiveManager(Connection connection)
  {
    super(connection);
  }
  
  public void disconnect()
  {
    super.disconnect();
    synchronized (commandPackets)
    {
      commandPackets.notifyAll();
    }
    synchronized (responsePackets)
    {
      responsePackets.notifyAll();
    }
  }
  
  public void run()
  {
    try
    {
      while (!isDisconnected()) {
        readAvailablePacket();
      }
    }
    catch (InterruptedIOException e)
    {
      disconnect(e);
    }
    catch (IOException e)
    {
      disconnect(e);
    }
  }
  
  public Packet getCommand(String type, long timeToWait)
    throws TimeoutException, DisconnectedException
  {
    synchronized (commandPackets)
    {
      long remainingTime = timeToWait;
      while ((!isDisconnected()) || (!commandPackets.isEmpty()))
      {
        Packet packet = removeCommandPacket(type);
        if (packet != null) {
          return packet;
        }
        if ((remainingTime < 0L) && (timeToWait != -1L)) {
          break;
        }
        long timeBeforeWait = System.currentTimeMillis();
        try
        {
          waitForPacketAvailable(remainingTime, commandPackets);
        }
        catch (InterruptedException localInterruptedException)
        {
          break;
        }
        long waitedTime = System.currentTimeMillis() - timeBeforeWait;
        remainingTime -= waitedTime;
      }
    }
    if (isDisconnected()) {
      throw new DisconnectedException("Runtime disconnected", getDisconnectedException());
    }
    throw new TimeoutException("Timed out waiting for command packet: " + type);
  }
  
  public Response getResponse(int requestSequence, long timeToWait)
    throws TimeoutException, DisconnectedException
  {
    synchronized (responsePackets)
    {
      long remainingTime = timeToWait;
      while (!isDisconnected())
      {
        Response response = removeResponsePacket(requestSequence);
        if (response != null) {
          return response;
        }
        if ((remainingTime < 0L) && (timeToWait != -1L)) {
          break;
        }
        long timeBeforeWait = System.currentTimeMillis();
        try
        {
          waitForPacketAvailable(remainingTime, responsePackets);
        }
        catch (InterruptedException localInterruptedException)
        {
          break;
        }
        long waitedTime = System.currentTimeMillis() - timeBeforeWait;
        remainingTime -= waitedTime;
      }
    }
    if (isDisconnected()) {
      throw new DisconnectedException("Runtime disconnected", getDisconnectedException());
    }
    synchronized (responsePackets)
    {
      timedOutPackets.add(new Integer(requestSequence));
    }
    throw new TimeoutException("Timed out waiting for packet: " + requestSequence);
  }
  
  private void waitForPacketAvailable(long timeToWait, Object lock)
    throws InterruptedException
  {
    if (timeToWait == 0L) {
      return;
    }
    if (timeToWait < 0L) {
      lock.wait();
    } else {
      lock.wait(timeToWait);
    }
  }
  
  private Packet removeCommandPacket(String type)
  {
    ListIterator iter = commandPackets.listIterator();
    while (iter.hasNext())
    {
      Packet packet = (Packet)iter.next();
      if ((type == null) || (packet.getType().equals(type)))
      {
        iter.remove();
        return packet;
      }
    }
    return null;
  }
  
  private Response removeResponsePacket(int requestSequence)
  {
    ListIterator iter = responsePackets.listIterator();
    while (iter.hasNext())
    {
      Response response = (Response)iter.next();
      if (requestSequence == response.getRequestSequence())
      {
        iter.remove();
        return response;
      }
    }
    return null;
  }
  
  private void addCommandPacket(Packet packet)
  {
    if (packet == null) {
      return;
    }
    synchronized (commandPackets)
    {
      commandPackets.add(packet);
      commandPackets.notifyAll();
    }
  }
  
  private void addResponsePacket(Response response)
  {
    if (response == null) {
      return;
    }
    synchronized (responsePackets)
    {
      if (!timedOutPackets.isEmpty())
      {
        Integer requestSeq = new Integer(response.getRequestSequence());
        if (timedOutPackets.remove(requestSeq)) {
          return;
        }
      }
      responsePackets.add(response);
      responsePackets.notifyAll();
    }
  }
  
  private void readAvailablePacket()
    throws IOException
  {
    if (getConnection().isOpen())
    {
      Packet packet = getConnection().readPacket();
      if ((packet instanceof Response)) {
        addResponsePacket((Response)packet);
      } else {
        addCommandPacket(packet);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.packet.PacketReceiveManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.packet;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.wst.jsdt.debug.transport.Connection;
import org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException;

public final class PacketSendManager
  extends PacketManager
{
  private final List outgoingPackets = new ArrayList();
  
  public PacketSendManager(Connection connection)
  {
    super(connection);
  }
  
  public void disconnect()
  {
    super.disconnect();
    synchronized (outgoingPackets)
    {
      outgoingPackets.notifyAll();
    }
  }
  
  public void run()
  {
    while (!isDisconnected()) {
      try
      {
        sendAvailablePackets();
      }
      catch (InterruptedException localInterruptedException)
      {
        disconnect();
      }
      catch (InterruptedIOException e)
      {
        disconnect(e);
      }
      catch (IOException e)
      {
        disconnect(e);
      }
    }
  }
  
  public void sendPacket(Packet packet)
    throws DisconnectedException
  {
    if (packet == null) {
      throw new IllegalArgumentException("You cannot send a null packet");
    }
    if (isDisconnected()) {
      throw new DisconnectedException("Runtime disconnected", getDisconnectedException());
    }
    synchronized (outgoingPackets)
    {
      outgoingPackets.add(packet);
      
      outgoingPackets.notifyAll();
    }
  }
  
  private void sendAvailablePackets()
    throws InterruptedException, IOException
  {
    synchronized (outgoingPackets)
    {
      while (outgoingPackets.size() == 0) {
        outgoingPackets.wait();
      }
      Object[] packetsToSend = outgoingPackets.toArray();
      outgoingPackets.clear();
    }
    Object[] packetsToSend;
    for (int i = 0; i < packetsToSend.length; i++) {
      getConnection().writePacket((Packet)packetsToSend[i]);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.packet.PacketSendManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.packet;

import java.util.Map;

public abstract interface Request
  extends Packet
{
  public abstract String getCommand();
  
  public abstract int getSequence();
  
  public abstract Map getArguments();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.packet.Request
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.packet;

import java.util.Map;

public abstract interface Response
  extends Packet
{
  public abstract String getCommand();
  
  public abstract int getRequestSequence();
  
  public abstract Map getBody();
  
  public abstract boolean isSuccess();
  
  public abstract boolean isRunning();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.packet.Response
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.socket;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.net.Socket;
import org.eclipse.wst.jsdt.debug.transport.Connection;
import org.eclipse.wst.jsdt.debug.transport.packet.Packet;

public abstract class SocketConnection
  implements Connection
{
  private Writer writer;
  private Reader reader;
  private Socket socket;
  
  public SocketConnection(Socket socket)
    throws IOException
  {
    if (socket == null) {
      throw new IllegalArgumentException("You cannot create a new SocketConnection on a null Socket");
    }
    this.socket = socket;
    writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
    reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
  }
  
  public boolean isOpen()
  {
    return !socket.isClosed();
  }
  
  public void close()
    throws IOException
  {
    socket.close();
  }
  
  public Writer getWriter()
  {
    return writer;
  }
  
  public abstract void writePacket(Packet paramPacket)
    throws IOException;
  
  public Reader getReader()
  {
    return reader;
  }
  
  public abstract Packet readPacket()
    throws IOException;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.socket.SocketConnection
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.socket;

import org.eclipse.wst.jsdt.debug.transport.ListenerKey;

public final class SocketListenerKey
  implements ListenerKey
{
  private String address;
  
  public SocketListenerKey(String address)
  {
    this.address = address;
  }
  
  public String address()
  {
    return address;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.socket.SocketListenerKey
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.transport.socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.wst.jsdt.debug.transport.Connection;
import org.eclipse.wst.jsdt.debug.transport.ListenerKey;
import org.eclipse.wst.jsdt.debug.transport.TransportService;

public abstract class SocketTransportService
  implements TransportService
{
  private Map listeners = new HashMap();
  
  public synchronized ListenerKey startListening(String address)
    throws IOException
  {
    String host = null;
    int port = 0;
    if (address != null)
    {
      String[] strings = address.split(":");
      if (strings.length == 2)
      {
        host = strings[0];
        port = Integer.parseInt(strings[1]);
      }
      else
      {
        port = Integer.parseInt(strings[0]);
      }
    }
    if (host == null) {
      host = "localhost";
    }
    ListenerKey key = new SocketListenerKey(host + ":" + port);
    ServerSocket serverSocket = new ServerSocket(port);
    listeners.put(key, serverSocket);
    return key;
  }
  
  public void stopListening(ListenerKey key)
    throws IOException
  {
    ServerSocket serverSocket = (ServerSocket)listeners.remove(key);
    if (serverSocket != null) {
      serverSocket.close();
    }
  }
  
  /* Error */
  public final ServerSocket getServerSocket(ListenerKey key)
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 115	org/eclipse/wst/jsdt/debug/transport/socket/SocketTransportService:listeners	Ljava/util/Map;
    //   4: dup
    //   5: astore_2
    //   6: monitorenter
    //   7: aload_0
    //   8: getfield 115	org/eclipse/wst/jsdt/debug/transport/socket/SocketTransportService:listeners	Ljava/util/Map;
    //   11: aload_1
    //   12: invokeinterface 136 2 0
    //   17: checkcast 62	java/net/ServerSocket
    //   20: aload_2
    //   21: monitorexit
    //   22: areturn
    //   23: aload_2
    //   24: monitorexit
    //   25: athrow
    // Line number table:
    //   Java source line #77	-> byte code offset #0
    //   Java source line #78	-> byte code offset #7
    //   Java source line #77	-> byte code offset #23
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	26	0	this	SocketTransportService
    //   0	26	1	key	ListenerKey
    //   5	19	2	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   7	22	23	finally
    //   23	25	23	finally
  }
  
  public Connection accept(ListenerKey key, long attachTimeout, long handshakeTimeout)
    throws IOException
  {
    ServerSocket serverSocket = getServerSocket(key);
    if (serverSocket == null) {
      throw new IllegalStateException("Accept failed. Not listening for address: key.address()");
    }
    int timeout = (int)attachTimeout;
    if (timeout > 0)
    {
      if (timeout > Integer.MAX_VALUE) {
        timeout = Integer.MAX_VALUE;
      }
      serverSocket.setSoTimeout(timeout);
    }
    Connection connection = getConnection(serverSocket.accept());
    handleAccept(connection);
    return connection;
  }
  
  public abstract void handleAccept(Connection paramConnection)
    throws IOException;
  
  public abstract SocketConnection getConnection(Socket paramSocket)
    throws IOException;
  
  public Connection attach(String address, long attachTimeout, long handshakeTimeout)
    throws IOException
  {
    String host = null;
    int port = 0;
    if (address != null)
    {
      String[] strings = address.split(":");
      if (strings.length == 2)
      {
        host = strings[0];
        port = Integer.parseInt(strings[1]);
      }
      else
      {
        port = Integer.parseInt(strings[0]);
      }
    }
    if (host == null) {
      host = "localhost";
    }
    Connection connection = getConnection(new Socket(host, port));
    handleAttach(connection);
    return connection;
  }
  
  public abstract void handleAttach(Connection paramConnection)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.transport.socket.SocketTransportService
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd