Skip to content

Commit

Permalink
Now you can pass an initial listener to not miss the very first queue…
Browse files Browse the repository at this point in the history
…d alerts.
  • Loading branch information
aldenml committed Feb 1, 2016
1 parent 6203b57 commit 63a4f47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/frostwire/jlibtorrent/Session.java
Expand Up @@ -53,7 +53,7 @@ public final class Session extends SessionHandle {
* @param settings
* @param logging
*/
public Session(SettingsPack settings, boolean logging) {
public Session(SettingsPack settings, boolean logging, AlertListener listener) {
super(createSession(settings, logging));

this.s = (session) super.s;
Expand All @@ -63,8 +63,11 @@ public Session(SettingsPack settings, boolean logging) {

this.listeners = new SparseArray<ArrayList<AlertListener>>();
this.listenerSnapshots = new SparseArray<AlertListener[]>();
this.running = true;
if (listener != null) {
addListener(listener);
}

this.running = true;
alertsLoop();

for (Pair<String, Integer> router : defaultRouters()) {
Expand All @@ -75,7 +78,7 @@ public Session(SettingsPack settings, boolean logging) {
}

public Session() {
this(new SettingsPack(), false);
this(new SettingsPack(), false, null);
}

public session getSwig() {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/frostwire/jlibtorrent/demo/SessionTest.java
Expand Up @@ -3,6 +3,7 @@
import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.LibTorrent;
import com.frostwire.jlibtorrent.Session;
import com.frostwire.jlibtorrent.SettingsPack;
import com.frostwire.jlibtorrent.alerts.Alert;

/**
Expand All @@ -17,9 +18,7 @@ public static void main(String[] args) throws Throwable {

System.out.println("Using libtorrent version: " + LibTorrent.fullVersion());

final Session s = new Session();

s.addListener(new AlertListener() {
AlertListener l = new AlertListener() {
@Override
public int[] types() {
return null;
Expand All @@ -29,9 +28,13 @@ public int[] types() {
public void alert(Alert<?> alert) {
System.out.println(alert.getType() + " - " + alert.getSwig().what() + " - " + alert.getSwig().message());
}
});
};

Session s = new Session(new SettingsPack(), false, l);

System.out.println("Press ENTER to exit");
System.in.read();

s.abort();
}
}

0 comments on commit 63a4f47

Please sign in to comment.