BundleException: Timed Out
I use OSGi and I create bundle called Server, which contains three classes and one of them is the bundle activator. I will publich the code of the three classes and then will write my problem. So the first class is calles "ServerThread" :
public class ServerThread extends Thread implements Constants {
private Socket socket;
private DataInputStream serverDataIn;
private DataOutputStream serverDataOut;
private int intCommand;
private HashMap statusHash;
public ServerThread(Socket socket) {
this.socket = socket;
}
public void run() {
try {
serverDataOut = new DataOutputStream(socket.getOutputStream());
serverDataIn = new DataInputStream(socket.getInputStream());
} catch (Exception ioe) {
ioe.printStackTrace();
}
try {
intCommand = serverDataIn.readInt();
} catch (IOException ioe) {
ioe.printStackTrace();
}
if (intCommand == LOGIN) {
String name = "";
String pass = "";
try {
name = serverDataIn.readUTF();
pass = serverDataIn.readUTF();
} catch (IOException e) {
e.printStackTrace();
}
if (!name.equals("") & !pass.equals("")) {
statusHash.put(name, ONLINE);
System.out.println("The user" + name + "is added in the statusHash");
try {
serverDataOut.writeInt(LOGIN);
serverDataOut.writeBoolean(true);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (intCommand == SEND_MESSAGE) {
String receiver = "";
String message = "";
try {
receiver = serverDataIn.readUTF();
message = serverDataIn.readUTF();
} catch (IOException e) {
e.printStackTrace();
}
if (!receiver.equals("") & !message.equals("")
& Integer.parseInt(statusHash.get(receiver).toString()) == ONLINE) {
System.out.println("Send message successful");
try {
serverDataOut.writeInt(SEND_MESSAGE);
serverDataOut.writeBoolean(true);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
===========================================================
The second class is :
public class OpenSocket extends Thread {
private static final int port = 8081;
private ServerSocket serverSocket;
private Socket socketServ;
private ServerThread serverThread = new ServerThread(socketServ);
public void run() {
try {
serverSocket = new ServerSocket(port);
System.out.println("Server port : " + port);
System.out.println("serverSocket : " + serverSocket);
} catch (IOException ioe) {
ioe.printStackTrace();
}
while (true) {
try {
socketServ = serverSocket.accept();
} catch (IOException e) {
e.printStackTrace();
}
serverThread.start();
}
}
}
===========================================================
And the Activator class is :
public class ServerActivator implements BundleActivator {
OpenSocket openSocket = new OpenSocket();
public void start(BundleContext arg0) throws Exception {
// TODO Auto-generated method stub
System.out.println("ServerActivator.start()");
openSocket.start();
}
public void stop(BundleContext arg0) throws Exception {
// TODO Auto-generated method stub
openSocket.stop();
}
}
===========================================================
So my problem is that when I install the bundle and start it, is thrown BundleException: Timed Out. Can someone tell me why this happens ?

