ProxyTransfer.java 2.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/**
 * $Revision$
 * $Date$
 *
 * Copyright (C) 1999-2005 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
 */
package org.jivesoftware.wildfire.filetransfer;

12 13 14
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.Cacheable;

15 16 17 18 19 20 21
import java.net.Socket;
import java.util.concurrent.Future;

/**
 * Tracks the different connections related to a file transfer. There are two connections, the
 * initiator and the target and when both connections are completed the transfer can begin.
 */
22
public class ProxyTransfer implements Cacheable {
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

    private String initiatorJID;

    private Socket initiatorSocket;

    private Socket targetSocket;

    private String targetJID;

    private String transferDigest;

    private String transferSession;
    
    private Future<?> future;

    public ProxyTransfer(String transferDigest, Socket targetSocket) {
        this.transferDigest = transferDigest;
        this.targetSocket = targetSocket;
    }

    public String getInitiatorJID() {
        return initiatorJID;
    }

    public void setInitiatorJID(String initiatorJID) {
        this.initiatorJID = initiatorJID;
    }

    public Socket getInitiatorSocket() {
        return initiatorSocket;
    }

    public void setInitiatorSocket(Socket initiatorSocket) {
        this.initiatorSocket = initiatorSocket;
    }

    public Socket getTargetSocket() {
        return targetSocket;
    }

    public void setTargetSocket(Socket targetSocket) {
        this.targetSocket = targetSocket;
    }

    public String getTargetJID() {
        return targetJID;
    }

    public void setTargetJID(String targetJID) {
        this.targetJID = targetJID;
    }

    public String getTransferDigest() {
        return transferDigest;
    }

    public void setTransferDigest(String transferDigest) {
        this.transferDigest = transferDigest;
    }

    public String getTransferSession() {
        return transferSession;
    }

    public void setTransferSession(String transferSession) {
        this.transferSession = transferSession;
    }

    /**
     * Returns true if the Bytestream is ready to be activated and the transfer can begin.
     *
     * @return Returns true if the Bytestream is ready to be activated.
     */
    public boolean isActivatable() {
        return ((initiatorSocket != null) && (targetSocket != null));
    }

    public void setTransferFuture(Future<?> future) {
        this.future = future;
    }
103 104 105 106 107 108 109 110 111 112 113 114

    public int getCachedSize() {
        // Approximate the size of the object in bytes by calculating the size
        // of each field.
        int size = 0;
        size += CacheSizes.sizeOfObject();              // overhead of object
        size += CacheSizes.sizeOfString(initiatorJID);
        size += CacheSizes.sizeOfString(targetJID);
        size += CacheSizes.sizeOfString(transferDigest);
        size += CacheSizes.sizeOfString(transferSession);
        return size;
    }
115
}