Search in sources :

Example 6 with RPException

use of com.biglybt.pifimpl.remote.RPException in project BiglyBT by BiglySoftware.

the class RPTracker method _process.

@Override
public RPReply _process(RPRequest request) {
    String method = request.getMethod();
    Object[] params = request.getParams();
    if (method.equals("host[Torrent,boolean]")) {
        try {
            Torrent torrent = params[0] == null ? null : (Torrent) ((RPTorrent) params[0])._setLocal();
            if (torrent == null) {
                throw (new RPException("Invalid torrent"));
            }
            TrackerTorrent tt = delegate.host(torrent, ((Boolean) params[1]).booleanValue());
            RPTrackerTorrent res = RPTrackerTorrent.create(tt);
            return (new RPReply(res));
        } catch (TrackerException e) {
            return (new RPReply(e));
        }
    } else if (method.equals("getTorrents")) {
        TrackerTorrent[] torrents = delegate.getTorrents();
        RPTrackerTorrent[] res = new RPTrackerTorrent[torrents.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = RPTrackerTorrent.create(torrents[i]);
        }
        return (new RPReply(res));
    }
    throw (new RPException("Unknown method: " + method));
}
Also used : TrackerException(com.biglybt.pif.tracker.TrackerException) RPTorrent(com.biglybt.pifimpl.remote.torrent.RPTorrent) Torrent(com.biglybt.pif.torrent.Torrent) TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) RPException(com.biglybt.pifimpl.remote.RPException) RPTorrent(com.biglybt.pifimpl.remote.torrent.RPTorrent) RPReply(com.biglybt.pifimpl.remote.RPReply) RPObject(com.biglybt.pifimpl.remote.RPObject)

Example 7 with RPException

use of com.biglybt.pifimpl.remote.RPException in project BiglyBT by BiglySoftware.

the class RPDownloadManager method _process.

@Override
public RPReply _process(RPRequest request) {
    String method = request.getMethod();
    Object[] params = request.getParams();
    if (method.equals("getDownloads")) {
        Download[] downloads = delegate.getDownloads();
        // unfortunately downloads with broken torrents can exist and have no associated
        // Torrent. Easiest fix here is to filter them out.
        RPDownload[] res = new RPDownload[downloads.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = RPDownload.create(downloads[i]);
        }
        return (new RPReply(res));
    } else if (method.equals("getDownloads[boolean]")) {
        Download[] downloads = delegate.getDownloads(((Boolean) request.getParams()[0]).booleanValue());
        RPDownload[] res = new RPDownload[downloads.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = RPDownload.create(downloads[i]);
        }
        return (new RPReply(res));
    } else if (method.equals("addDownload[Torrent]")) {
        try {
            RPTorrent torrent = (RPTorrent) request.getParams()[0];
            Download res = delegate.addDownload((Torrent) torrent._setLocal());
            return (new RPReply(RPDownload.create(res)));
        } catch (DownloadException e) {
            throw (new RPException("DownloadManager::addDownload failed", e));
        }
    } else if (method.equals("addDownload[Torrent,String,String]")) {
        try {
            RPTorrent torrent = (RPTorrent) request.getParams()[0];
            File f1 = params[1] == null ? null : new File((String) params[1]);
            File f2 = params[2] == null ? null : new File((String) params[2]);
            Download res = delegate.addDownload((Torrent) torrent._setLocal(), f1, f2);
            return (new RPReply(RPDownload.create(res)));
        } catch (DownloadException e) {
            throw (new RPException("DownloadManager::addDownload failed", e));
        }
    } else if (method.equals("addDownload[URL]")) {
        try {
            delegate.addDownload((URL) request.getParams()[0]);
        } catch (DownloadException e) {
            throw (new RPException("DownloadManager::addDownload failed", e));
        }
        return (new RPReply(null));
    } else if (method.equals("pauseDownloads")) {
        delegate.pauseDownloads();
        return (null);
    } else if (method.equals("resumeDownloads")) {
        delegate.resumeDownloads();
        return (null);
    } else if (method.equals("stopAllDownloads")) {
        delegate.stopAllDownloads();
        return (null);
    } else if (method.equals("startAllDownloads")) {
        delegate.startAllDownloads();
        return (null);
    }
    throw (new RPException("Unknown method: " + method));
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) RPTorrent(com.biglybt.pifimpl.remote.torrent.RPTorrent) RPException(com.biglybt.pifimpl.remote.RPException) RPTorrent(com.biglybt.pifimpl.remote.torrent.RPTorrent) RPReply(com.biglybt.pifimpl.remote.RPReply) RPObject(com.biglybt.pifimpl.remote.RPObject) File(java.io.File)

Example 8 with RPException

use of com.biglybt.pifimpl.remote.RPException in project BiglyBT by BiglySoftware.

the class RPIPFilter method _process.

@Override
public RPReply _process(RPRequest request) {
    String method = request.getMethod();
    Object[] params = request.getParams();
    if (method.equals("createAndAddRange[String,String,String,boolean]")) {
        IPRange range = delegate.createAndAddRange((String) params[0], (String) params[1], (String) params[2], ((Boolean) params[3]).booleanValue());
        if (range == null) {
            return (new RPReply(null));
        } else {
            RPIPRange rp_range = RPIPRange.create(range);
            return (new RPReply(rp_range));
        }
    } else if (method.equals("getRanges")) {
        IPRange[] ranges = delegate.getRanges();
        RPIPRange[] rp_ranges = new RPIPRange[ranges.length];
        for (int i = 0; i < ranges.length; i++) {
            rp_ranges[i] = RPIPRange.create(ranges[i]);
        }
        return (new RPReply(rp_ranges));
    } else if (method.equals("save")) {
        try {
            delegate.save();
            return (null);
        } catch (IPFilterException e) {
            return (new RPReply(e));
        }
    } else if (method.equals("getInRangeAddressesAreAllowed")) {
        return (new RPReply(Boolean.valueOf(delegate.getInRangeAddressesAreAllowed())));
    } else if (method.equals("setInRangeAddressesAreAllowed[boolean]")) {
        delegate.setInRangeAddressesAreAllowed(((Boolean) params[0]).booleanValue());
        return (null);
    } else if (method.equals("isEnabled")) {
        return (new RPReply(Boolean.valueOf(delegate.isEnabled())));
    } else if (method.equals("setEnabled[boolean]")) {
        delegate.setEnabled(((Boolean) params[0]).booleanValue());
        return (null);
    } else if (method.equals("isInRange[String]")) {
        return (new RPReply(Boolean.valueOf(delegate.isInRange((String) params[0]))));
    }
    throw (new RPException("Unknown method: " + method));
}
Also used : RPException(com.biglybt.pifimpl.remote.RPException) RPReply(com.biglybt.pifimpl.remote.RPReply) RPObject(com.biglybt.pifimpl.remote.RPObject)

Example 9 with RPException

use of com.biglybt.pifimpl.remote.RPException in project BiglyBT by BiglySoftware.

the class RPTorrentDownloader method download.

// ************************************************************************
@Override
public Torrent download() throws TorrentException {
    try {
        RPTorrent resp = (RPTorrent) _dispatcher.dispatch(new RPRequest(this, "download", null)).getResponse();
        resp._setRemote(_dispatcher);
        return (resp);
    } catch (RPException e) {
        if (e.getCause() instanceof TorrentException) {
            throw ((TorrentException) e.getCause());
        }
        throw (e);
    }
}
Also used : RPRequest(com.biglybt.pifimpl.remote.RPRequest) RPException(com.biglybt.pifimpl.remote.RPException) TorrentException(com.biglybt.pif.torrent.TorrentException)

Example 10 with RPException

use of com.biglybt.pifimpl.remote.RPException in project BiglyBT by BiglySoftware.

the class RPTorrentManager method getURLDownloader.

// ************************************************************************
@Override
public TorrentDownloader getURLDownloader(URL url) throws TorrentException {
    try {
        RPTorrentDownloader resp = (RPTorrentDownloader) _dispatcher.dispatch(new RPRequest(this, "getURLDownloader[URL]", new Object[] { url })).getResponse();
        resp._setRemote(_dispatcher);
        return (resp);
    } catch (RPException e) {
        if (e.getCause() instanceof TorrentException) {
            throw ((TorrentException) e.getCause());
        }
        throw (e);
    }
}
Also used : RPRequest(com.biglybt.pifimpl.remote.RPRequest) RPException(com.biglybt.pifimpl.remote.RPException) RPObject(com.biglybt.pifimpl.remote.RPObject)

Aggregations

RPException (com.biglybt.pifimpl.remote.RPException)13 RPObject (com.biglybt.pifimpl.remote.RPObject)11 RPRequest (com.biglybt.pifimpl.remote.RPRequest)8 RPReply (com.biglybt.pifimpl.remote.RPReply)5 Torrent (com.biglybt.pif.torrent.Torrent)3 TorrentException (com.biglybt.pif.torrent.TorrentException)3 TrackerException (com.biglybt.pif.tracker.TrackerException)2 RPTorrent (com.biglybt.pifimpl.remote.torrent.RPTorrent)2 TrackerTorrent (com.biglybt.pif.tracker.TrackerTorrent)1 File (java.io.File)1 URL (java.net.URL)1