KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdi > internal > connect > PacketManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdi.internal.connect;
12
13
14 import java.io.IOException JavaDoc;
15
16 import com.sun.jdi.connect.spi.Connection;
17
18 /**
19  * This class implements threads that receive/send packets from/to the Virtual Machine.
20  *
21  */

22 public abstract class PacketManager implements Runnable JavaDoc {
23     /** Connector that performs IO to Virtual Machine. */
24     private Connection fConnection;
25     /** Thread that handles the communication the other way (e.g. if we are sending, the receiving thread). */
26     private Thread JavaDoc fPartnerThread;
27     private IOException JavaDoc fDisconnectException;
28     
29     /**
30      * Creates new PacketManager.
31      */

32     protected PacketManager(Connection connection) {
33         fConnection = connection;
34     }
35     
36     public Connection getConnection() {
37         return fConnection;
38     }
39     
40     /**
41      * Used to indicate that an IO exception occurred, closes connection to Virtual Machine.
42      *
43      * @param disconnectException the IOException that occurred
44      */

45     public void disconnectVM(IOException JavaDoc disconnectException) {
46         fDisconnectException= disconnectException;
47         disconnectVM();
48     }
49
50     /**
51      * Closes connection to Virtual Machine.
52      */

53     public void disconnectVM() {
54         try {
55             fConnection.close();
56         } catch (IOException JavaDoc e) {
57             fDisconnectException = e;
58         }
59         // Interrupt the sending thread if we are the receiving thread and vice versa.
60
if (fPartnerThread != null) {
61             fPartnerThread.interrupt();
62         }
63     }
64     
65     /**
66      * @return Returns whether an IO exception has occurred.
67      */

68     public boolean VMIsDisconnected() {
69         return fConnection == null || !fConnection.isOpen();
70     }
71     
72     /**
73      * Returns the IOException that caused this packet manager to disconnect or
74      * <code>null</code> if none.
75      */

76     public IOException JavaDoc getDisconnectException() {
77         return fDisconnectException;
78     }
79     
80     /**
81      * Assigns thread of partner, to be notified if we have an IO exception.
82      */

83     public void setPartnerThread(Thread JavaDoc thread) {
84         fPartnerThread = thread;
85     }
86 }
87
Popular Tags