01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.util;
17:
18: import javax.naming.InitialContext;
19: import javax.naming.Context;
20: import java.net.Socket;
21: import java.io.OutputStream;
22: import java.util.Properties;
23:
24: /**
25: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
26: */
27: public class Connect {
28:
29: public static boolean connect(int tries, String host, int port) {
30:
31: try {
32:
33: Socket socket = new Socket(host, port);
34:
35: OutputStream out = socket.getOutputStream();
36:
37: } catch (Exception e) {
38:
39: if (tries < 2) {
40:
41: return false;
42:
43: } else {
44:
45: try {
46:
47: Thread.sleep(2000);
48:
49: } catch (Exception e2) {
50:
51: e.printStackTrace();
52:
53: }
54:
55: return connect(--tries, host, port);
56:
57: }
58:
59: }
60:
61: return true;
62: }
63:
64: }
|