/** Executes once on change if change is detected */
 protected synchronized void onChange() {
   List<DataSourceListener> listeners = fileSystemDataSource.listeners;
   for (DataSourceListener listener : listeners) {
     listener.onDeploymentAdded();
   }
   storage.clear();
 }
Exemple #2
0
 @SuppressWarnings("unchecked")
 private void notifyDataListeners(DataSetEvent e) {
   List<DataSourceListener> l;
   synchronized (this) {
     l = (List<DataSourceListener>) m_dataListeners.clone();
   }
   if (l.size() > 0) {
     for (DataSourceListener ds : l) {
       ds.acceptDataSet(e);
     }
   }
 }
  public long open(String uri) throws IOException {
    if (opened) {
      throw new IOException("Attempting to re-open an OPENED datasource for uri " + uri);
    }
    log.debug("[{}]:Open(): {}", session, uri);
    try {
      String host = getHost(uri);
      this.uri = uri;
      bytesRead = 0;
      bytesPos = 0;
      bytesAvailable = 0;

      circularByteBuffer = new CircularByteBuffer(PushBufferDataSource.PIPE_SIZE);
      in = circularByteBuffer.getInputStream();
      out = circularByteBuffer.getOutputStream();

      remoteServer = new Socket();
      remoteServer.connect(new java.net.InetSocketAddress(host, 7818), 2000);
      this.remoteReader = new DataInputStream(remoteServer.getInputStream());
      this.remoteWriter = remoteServer.getOutputStream();

      sendStringCommandWithReply("OPEN " + getPath(uri));
      String strSize = sendStringCommandWithReply("SIZE");
      if (strSize != null) {
        try {
          size = Long.parseLong(strSize.split(" ")[0]);
        } catch (Throwable t) {
          log.error("[{}]:Failed to get Size", session, t);
          size = -1;
        }
      }
      log.debug("SIZE got {} for {}", size, uri);
      opened = true;
      if (listener != null) {
        listener.onOpen(this);
      }
    } catch (Throwable t) {
      log.error("[{}]:Unable to open: {}", session, uri, t);
    }

    return size;
  }
  public void close() {
    log.debug("[{}]:Close()", session);
    try {
      if (remoteServer != null) {
        try {
          sendStringCommandWithReply("CLOSE");
        } catch (Throwable t) {
        }
        remoteServer.close();
      }
    } catch (IOException e) {
      // e.printStackTrace();
    }
    remoteServer = null;
    remoteReader = null;
    remoteWriter = null;

    try {
      circularByteBuffer.clear();
      if (in != null) in.close();
    } catch (IOException e) {
      // e.printStackTrace();
    }
    try {
      if (out != null) out.close();
    } catch (IOException e) {
      // e.printStackTrace();
    }

    buffer = null;
    circularByteBuffer = null;
    in = null;
    out = null;

    if (listener != null) {
      listener.onClose(this);
    }
    // MiniClient.get().getHttpBridge().removeSession(session);

    opened = false;
  }