@Override
 public void stop() {
   for (FileSender theSender : mySendingFiles.values()) {
     theSender.stop();
   }
   for (FileReceiver theReceiver : myReceivingFiles.values()) {
     theReceiver.stop();
   }
 }
Exemplo n.º 2
0
 @Override
 public void handle(SelectionKey key, Selector selector) {
   if (null == key.attachment()) {
     System.out.println("key.attachment() is null ... ");
     return;
   }
   FileSender sender = (FileSender) key.attachment();
   System.out.println("get write request.attachemnt fileName : " + sender);
   // send file and register read
   sender.send((SocketChannel) key.channel());
 }
  public FileTransferHandler sendFile(final File aFile, final String aPeer) {
    // create a new FilePacketIO for this file transfer
    FilePacketIO theIO = FilePacketIO.createForRead(aFile, myPacketSize);
    // store it
    FileSender theFileSender = new FileSender(aPeer, theIO, this);
    mySendingFiles.put(theIO.getId(), theFileSender);
    notifyNewTransfer(theIO.getId());
    theFileSender.startAsync(myFileSenderService);

    return new FileTransferHandler(theIO.getId(), this);
  }
Exemplo n.º 4
0
 public void init() {
   sshSession = new SSHSession();
   Session session = sshSession.openSession("root", "123456", "10.16.0.110", 22);
   fileSender = new FileSender(session);
   boolean isUploaded = fileSender.upload("/opt/", new File("E:/akka-demo/akka-demo.iml"));
   session.disconnect();
 }
 @Override
 public void removeFinished() {
   synchronized (LOCK) {
     for (Iterator<String> theTransferIds = mySendingFiles.keySet().iterator();
         theTransferIds.hasNext(); ) {
       String theTransferId = theTransferIds.next();
       FileSender theSender = mySendingFiles.get(theTransferId);
       if (theSender.isComplete()) {
         mySendingFiles.remove(theTransferId);
         notifyTransferRemoved(theTransferId);
       }
     }
     for (Iterator<String> theTransferIds = myReceivingFiles.keySet().iterator();
         theTransferIds.hasNext(); ) {
       String theTransferId = theTransferIds.next();
       FileReceiver theReceiver = myReceivingFiles.get(theTransferId);
       if (theReceiver.isComplete()) {
         myReceivingFiles.remove(theTransferId);
         notifyTransferRemoved(theTransferId);
       }
     }
   }
 }