1 |
iliev |
913 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1143 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
913 |
* |
6 |
|
|
* This file is part of JSampler. |
7 |
|
|
* |
8 |
|
|
* JSampler is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License version 2 |
10 |
|
|
* as published by the Free Software Foundation. |
11 |
|
|
* |
12 |
|
|
* JSampler is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with JSampler; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
|
|
* MA 02111-1307 USA |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
package org.jsampler.task; |
24 |
|
|
|
25 |
|
|
import java.net.InetSocketAddress; |
26 |
|
|
import java.net.Socket; |
27 |
|
|
|
28 |
|
|
import java.util.logging.Level; |
29 |
|
|
|
30 |
|
|
import org.jsampler.CC; |
31 |
|
|
import org.jsampler.HF; |
32 |
|
|
|
33 |
|
|
import static org.jsampler.JSI18n.i18n; |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
/** |
37 |
|
|
* Establishes the connection to LinuxSampler used by the LS Console. |
38 |
|
|
* @author Grigor Iliev |
39 |
|
|
*/ |
40 |
|
|
public class LSConsoleConnect extends EnhancedTask<Socket> { |
41 |
|
|
private Socket oldSocket; |
42 |
|
|
|
43 |
|
|
/** Creates a new instance of <code>LSConsoleConnect</code>. */ |
44 |
|
|
public |
45 |
|
|
LSConsoleConnect() { this(null); } |
46 |
|
|
|
47 |
|
|
/** |
48 |
|
|
* Creates a new instance of <code>LSConsoleConnect</code>. |
49 |
|
|
* @param oldSocket The socket to close. |
50 |
|
|
*/ |
51 |
|
|
public |
52 |
|
|
LSConsoleConnect(Socket oldSocket) { |
53 |
|
|
setTitle("LSConsoleConnect_task"); |
54 |
|
|
setDescription(i18n.getMessage("LSConsoleConnect.description")); |
55 |
|
|
|
56 |
|
|
this.oldSocket = oldSocket; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
/** The entry point of the task. */ |
60 |
|
|
public void |
61 |
|
|
run() { |
62 |
|
|
try { |
63 |
iliev |
1688 |
String address = CC.getCurrentServer().getAddress(); |
64 |
|
|
int port = CC.getCurrentServer().getPort(); |
65 |
iliev |
913 |
|
66 |
|
|
if(oldSocket != null) oldSocket.close(); |
67 |
|
|
InetSocketAddress sockAddr = new InetSocketAddress(address, port); |
68 |
|
|
|
69 |
|
|
int soTimeout = 10000; |
70 |
|
|
Socket sock = new Socket(); |
71 |
|
|
sock.bind(null); |
72 |
|
|
sock.connect(sockAddr, soTimeout); |
73 |
|
|
sock.setSoTimeout(soTimeout); |
74 |
|
|
sock.setTcpNoDelay(true); |
75 |
|
|
|
76 |
|
|
setResult(sock); |
77 |
|
|
} catch(Exception x) { |
78 |
|
|
String err = getDescription() + ": " + HF.getErrorMessage(x); |
79 |
|
|
CC.getLogger().log(Level.INFO, err, x); |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
} |