123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package com.rdlze.radializebase.utils;
- import java.rmi.NotBoundException;
- import java.rmi.RemoteException;
- import java.rmi.registry.LocateRegistry;
- import java.rmi.registry.Registry;
- import java.sql.Timestamp;
- import com.rdlze.radializebase.interfaces.InterfaceSearchServer;
- import com.rdlze.radializebase.notification.Notifier;
- import com.rdlze.radializeutils.notification.Notification;
- import com.rdlze.radializeutils.objects.IndexResponse;
- /**
- * Utils for rdlz backend tasks
- *
- * @author kledilson
- *
- */
- public class RdlzComponents {
- /**
- * Connects to Rdlz broker
- *
- * @param ip
- * @param serviceName
- */
- public static void connectToBroker(String ip, String serviceName, int port) {
- Notifier.init(ip, serviceName, port);
- System.out.println("Conectou ao broker do Radialize");
- }
- /**
- * Connects to Rdlz SearchServer
- *
- * @param ip
- * @param serviceName
- * @return
- * @throws RemoteException
- * @throws NotBoundException
- */
- public static InterfaceSearchServer getSearchServerFacade(String ip,
- String serviceName) throws RemoteException, NotBoundException {
- Registry registry = LocateRegistry.getRegistry(ip);
- InterfaceSearchServer iSS = (InterfaceSearchServer) registry
- .lookup(serviceName);
- System.out.println("Pegou fachada do SearchServer");
- return iSS;
- }
- /**
- * Send notification to radialize's broker with new content
- *
- * @param artist
- * @param song
- * @param response
- * @throws RemoteException
- */
- public static void sendNotification(String artist, String song,
- IndexResponse response) throws RemoteException {
- Notification notification = new Notification(0);
- notification.setRadioId(-1);
- if (response.getMBResp() != null) {
- notification.setMusicBrainzResponse(response.getMBResp());
- }
- if (response.getMBResp() != null
- && response.getMBResp().getArtist() != null
- && response.getMBResp().getArtist().getName() != null
- && !response.getMusicBrainzArtistId().equals("-1")
- && (!(response.getMBResp().getArtist().getName()).equals("") || !(response
- .getMBResp().getArtist().getName()).equals("-1"))) {
- artist = response.getMBResp().getArtist().getName();
- }
- if (response.getMBResp() != null
- && response.getMBResp().getSong() != null
- && !response.getMBResp().getIdSongMB().equals("-1")
- && (!(response.getMBResp().getSong()).equals("") || !(response
- .getMBResp().getSong()).equals("-1"))) {
- song = response.getMBResp().getSong();
- }
- notification.setArtistName(artist);
- notification.setSongName(song);
- notification.setArtistId(response.getArtistId());
- notification.setSongId(response.getMusicId());
- notification.setMediaId(response.getMediaId());
- notification.setMedia(artist + song);
- notification.setTrack(true);
- notification.setNotDisplayable();
- notification.setStartTime(new Timestamp(0));
- notification.setEndTime(new Timestamp(0));
- notification.setPath("");
- notification.setMusicBrainzArtistId(response.getMusicBrainzArtistId());
- notification.setMusicBrainzSongId(response.getMusicBrainzMusicId());
- notification.setNotificationType(0);
- Notifier.notify(notification);
- }
- }
|