Package de.innovationgate.eclipse.wgadesigner.models

Source Code of de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.models;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.codehaus.xfire.transport.http.CommonsHttpMessageSender;

import de.innovationgate.wgaservices.ClientFactory;
import de.innovationgate.wgaservices.WGACoreServices;
import de.innovationgate.wgaservices.types.RemoteSession;

public class WGARemoteServer {
  private String _name;
  private URL _url;
  private String _user;
  private String _password;

  private transient WGACoreServices _services;
  private transient RemoteSession _session;

  public WGACoreServices getServices() {
    return _services;
  }

  public RemoteSession getSession() {
    return _session;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj instanceof WGARemoteServer) {
      WGARemoteServer wrsrv = (WGARemoteServer) obj;
      return _name.equals(wrsrv.getName());
    }
    return false;
  }

  public WGARemoteServer(String name, URL url, String user, String password) {
    super();
    _name = name;
    _url = url;
    _user = user;
    _password = password;

  }

  public String getName() {
    return _name;
  }

  public void setName(String name) {
    _name = name;
  }

  public URL getUrl() {
    return _url;
  }

  public void setUrl(URL url) {
    _url = url;
  }

  public String getUser() {
    return _user;
  }

  public void setUser(String user) {
    _user = user;
  }

  public String getPassword() {
    return _password;
  }

  public void setPassword(String password) {
    _password = password;
  }

   public void connectToServer(final int connectTimeoutMillis, final int readTimeoutMillis) throws Exception {       
        ExecutorService executor = Executors.newSingleThreadExecutor();    
        Future<Boolean> future = executor.submit(new Callable<Boolean>() {
            public Boolean call() throws Exception {
                HttpClientParams params = new HttpClientParams();
                params.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, connectTimeoutMillis);
                params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, readTimeoutMillis);
                Map<String,Object> props = new HashMap<String, Object>();
                props.put(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS, params);
                _services = ClientFactory.createCoreServiceClient(_url.toString(), props);
                _session = _services.adminLogin(_user, _password);
                return Boolean.TRUE;
            }
        });
        future.get((connectTimeoutMillis + readTimeoutMillis), TimeUnit.MILLISECONDS);
    }
 
  public void connectToServer() throws Exception {   
    ExecutorService executor = Executors.newSingleThreadExecutor();   
        Future<Boolean> future = executor.submit(new Callable<Boolean>() {
            public Boolean call() throws Exception {
              _services = ClientFactory.createCoreServiceClient(_url.toString());
        _session = _services.adminLogin(_user, _password);
        return Boolean.TRUE;
            }
        });
         future.get(1000 * 10, TimeUnit.MILLISECONDS);
  }
}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.