Skip to content

Instantly share code, notes, and snippets.

@vemacs
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save vemacs/aa1565456b76022ed847 to your computer and use it in GitHub Desktop.

Select an option

Save vemacs/aa1565456b76022ed847 to your computer and use it in GitHub Desktop.
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private Skype skype;
public void loadSkype() {
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
Skype oldSkype = skype; // get instance of old skype
Skype newSkype = Skype.login(username, password); // Set up new skype
System.out.println("Logged in with username " + username);
newSkype.getEventDispatcher().registerListener(new Listener() {
@EventHandler
public void onMessage(final MessageReceivedEvent e) {
}
});
newSkype.subscribe();
skype = newSkype; // reassign new skype to current skype
System.out.println("Reassigned new Skype");
if (oldSkype != null) {
try {
oldSkype.logout();
System.out.println("Logged out previous instance");
} catch (IOException ignored) {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, 0, 30, TimeUnit.MINUTES);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment