Added volume to client plus other fixes
[stereo.git] / DAAPLib / src / util / command / Update.java
blob82e0dd1ff69a1c36dc82312787f4886f61e52bcd
1 package util.command;
3 import interfaces.DJInterface;
5 import java.util.Map;
7 import notification.LibraryListener;
8 import util.node.Node;
9 import dacp.DACPTreeBuilder;
11 public class Update implements Command, LibraryListener {
13 private int revision;
15 public void init(Map<String, String> args) {
16 String rev = args.get("revision-number");
17 if (rev == null) {
18 revision = 0;
19 System.err.println("update: revision number not present");
21 else {
22 try {
23 revision = Integer.parseInt(rev);
25 catch (NumberFormatException ex) {
26 throw new IllegalArgumentException("revision number " + rev + " is not valid");
31 public Node run(DJInterface dj) {
33 if (this.revision >= dj.library().version()) {
35 dj.library().registerLibraryListener(this);
37 try {
38 synchronized (this) {
39 this.wait(10000); //wait 10 seconds if nothing has changed
41 } catch (InterruptedException e) {
42 e.printStackTrace();
45 dj.library().removeLibraryListener(this);
48 //TODO use version to check whether update is needed
49 return DACPTreeBuilder.buildUpdateResponse(dj.library().version());
52 public void libraryVersionChanged(int version) {
53 synchronized (this) {
54 this.notify();