author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 04 Nov 2010 15:22:02 -0700 | |
changeset 495 | 0008ebdc0ec0 |
parent 484 | f5df819c1852 |
permissions | -rw-r--r-- |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
1 |
/******************************************************************************* |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
3 |
* All rights reserved. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
8 |
* |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
* Contributors: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
12 |
* Description: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
13 |
* Overview: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
14 |
* Details: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
15 |
* Platforms/Drives/Compatibility: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
16 |
* Assumptions/Requirement/Pre-requisites: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
17 |
* Failures and causes: |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
18 |
*******************************************************************************/ |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
19 |
package org.symbian.tools.tmw.debug.internal.launch; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
20 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
21 |
import java.io.IOException; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
22 |
import java.net.ServerSocket; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
23 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
24 |
import org.symbian.tools.tmw.debug.internal.Activator; |
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
25 |
|
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
26 |
public abstract class PortPolicy { |
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
27 |
private static class NewPortEachTime extends PortPolicy { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
28 |
@Override |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
29 |
protected int getPort() { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
30 |
return getOpenPort(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
31 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
32 |
} |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
33 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
34 |
public static final PortPolicy INSTANCE; |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
35 |
static { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
36 |
INSTANCE = new NewPortEachTime(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
37 |
} |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
38 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
39 |
public static synchronized int getPortNumber() { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
40 |
return INSTANCE.getPort(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
41 |
} |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
42 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
43 |
public int getOpenPort() { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
44 |
try { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
45 |
final ServerSocket socket = new ServerSocket(0); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
46 |
int port = socket.getLocalPort(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
47 |
socket.close(); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
48 |
return port; |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
49 |
} catch (IOException e) { |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
50 |
Activator.log(e); |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
51 |
return 7222; |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
52 |
} |
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
53 |
} |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
54 |
|
484
f5df819c1852
Checkstyle was used to review coding conventions
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
471
diff
changeset
|
55 |
protected abstract int getPort(); |
471
06589bf52fa7
Refactoring and restructuring the repository
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
56 |
} |