use of com.github.hakko.musiccabinet.domain.model.aggr.Scrobble in project musiccabinet by hakko.
the class ScrobbleService method receive.
@SuppressWarnings("unchecked")
protected void receive() throws ApplicationException {
Message<Scrobble> message;
while ((message = (Message<Scrobble>) scrobbleChannel.receive()) != null) {
Scrobble scrobble = message.getPayload();
Scrobble previous = getPrevious(scrobble);
if (previous != null && tooClose(scrobble, previous) && scrobble.getTrack().getId() == previous.getTrack().getId()) {
LOG.debug("Same track was scrobbled just recently, ignore.");
} else {
addScrobble(scrobble);
WSResponse wsResponse = nowPlayingClient.updateNowPlaying(scrobble);
if (!wsResponse.wasCallSuccessful()) {
LOG.debug("Could not update now playing status at last.fm.");
LOG.debug("Nowplaying response: " + wsResponse);
}
}
}
}
use of com.github.hakko.musiccabinet.domain.model.aggr.Scrobble in project musiccabinet by hakko.
the class ScrobbleService method addScrobble.
private void addScrobble(Scrobble scrobble) {
ConcurrentLinkedDeque<Scrobble> deque = userScrobbles.get(scrobble.getLastFmUser());
Scrobble tail;
while ((tail = deque.peekLast()) != null && tooClose(tail, scrobble)) {
// indicates the occurrence of a previous track that was played for a few
// seconds, and that should be removed
deque.pollLast();
}
deque.add(scrobble);
}
use of com.github.hakko.musiccabinet.domain.model.aggr.Scrobble in project musiccabinet by hakko.
the class ScrobbleService method scrobbleTracks.
protected void scrobbleTracks() throws ApplicationException {
scrobbleFailedTracks();
Scrobble head;
for (LastFmUser lastFmUser : userScrobbles.keySet()) {
ConcurrentLinkedDeque<Scrobble> deque = userScrobbles.get(lastFmUser);
while ((head = deque.peekFirst()) != null && !tooClose(head, new DateTime())) {
playCountDao.addPlayCount(head.getLastFmUser(), head.getTrack());
WSResponse wsResponse = scrobbleClient.scrobble(head);
if (!wsResponse.wasCallSuccessful()) {
LOG.warn("scrobbling " + head + " failed! Add for re-sending.");
LOG.debug("Scrobble response: " + wsResponse);
failedScrobbles.add(head);
}
deque.pollFirst();
}
}
}
use of com.github.hakko.musiccabinet.domain.model.aggr.Scrobble in project musiccabinet by hakko.
the class ScrobbleService method scrobble.
/* Async method that registers scrobbles and delegates submissions, in case last.fm is down.
*
* Submission: Whether this is a "scrobble" or a "now playing" notification.
*/
public void scrobble(String lastFmUsername, Track track, boolean submission) {
LastFmUser lastFmUser = lastFmDao.getLastFmUser(lastFmUsername);
Scrobble scrobble = new Scrobble(lastFmUser, track, submission);
scrobbleChannel.send(new GenericMessage<Scrobble>(scrobble));
if (!started.getAndSet(true)) {
startScrobblingService();
}
}
use of com.github.hakko.musiccabinet.domain.model.aggr.Scrobble in project musiccabinet by hakko.
the class ScrobbleService method scrobbleFailedTracks.
protected void scrobbleFailedTracks() throws ApplicationException {
while (failedScrobbles.size() > 0) {
LOG.debug("Queue of failed scrobbles consists of " + failedScrobbles.size() + " elements.");
Scrobble firstFailed = failedScrobbles.get(0);
WSResponse wsResponse = scrobbleClient.scrobble(firstFailed);
if (wsResponse.wasCallSuccessful()) {
LOG.debug("Failed scrobble was re-sent.");
failedScrobbles.remove(0);
} else {
LOG.debug("Failed scrobble could not be re-sent. Wait a minute before trying again.");
LOG.debug("Response: " + wsResponse);
return;
}
}
}
Aggregations