Няма описание

c83651cc3980f95fa6829f07b246a9bb5f9e4b1d.svn-base 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.rdlze.radializebase.utils;
  2. import java.rmi.NotBoundException;
  3. import java.rmi.RemoteException;
  4. import java.rmi.registry.LocateRegistry;
  5. import java.rmi.registry.Registry;
  6. import java.sql.Timestamp;
  7. import com.rdlze.radializebase.interfaces.InterfaceSearchServer;
  8. import com.rdlze.radializebase.notification.Notifier;
  9. import com.rdlze.radializeutils.notification.Notification;
  10. import com.rdlze.radializeutils.objects.IndexResponse;
  11. /**
  12. * Utils for rdlz backend tasks
  13. *
  14. * @author kledilson
  15. *
  16. */
  17. public class RdlzComponents {
  18. /**
  19. * Connects to Rdlz broker
  20. *
  21. * @param ip
  22. * @param serviceName
  23. */
  24. public static void connectToBroker(String ip, String serviceName, int port) {
  25. Notifier.init(ip, serviceName, port);
  26. System.out.println("Conectou ao broker do Radialize");
  27. }
  28. /**
  29. * Connects to Rdlz SearchServer
  30. *
  31. * @param ip
  32. * @param serviceName
  33. * @return
  34. * @throws RemoteException
  35. * @throws NotBoundException
  36. */
  37. public static InterfaceSearchServer getSearchServerFacade(String ip,
  38. String serviceName) throws RemoteException, NotBoundException {
  39. Registry registry = LocateRegistry.getRegistry(ip);
  40. InterfaceSearchServer iSS = (InterfaceSearchServer) registry
  41. .lookup(serviceName);
  42. System.out.println("Pegou fachada do SearchServer");
  43. return iSS;
  44. }
  45. /**
  46. * Send notification to radialize's broker with new content
  47. *
  48. * @param artist
  49. * @param song
  50. * @param response
  51. * @throws RemoteException
  52. */
  53. public static void sendNotification(String artist, String song,
  54. IndexResponse response) throws RemoteException {
  55. Notification notification = new Notification(0);
  56. notification.setRadioId(-1);
  57. if (response.getMBResp() != null) {
  58. notification.setMusicBrainzResponse(response.getMBResp());
  59. }
  60. if (response.getMBResp() != null
  61. && response.getMBResp().getArtist() != null
  62. && response.getMBResp().getArtist().getName() != null
  63. && !response.getMusicBrainzArtistId().equals("-1")
  64. && (!(response.getMBResp().getArtist().getName()).equals("") || !(response
  65. .getMBResp().getArtist().getName()).equals("-1"))) {
  66. artist = response.getMBResp().getArtist().getName();
  67. }
  68. if (response.getMBResp() != null
  69. && response.getMBResp().getSong() != null
  70. && !response.getMBResp().getIdSongMB().equals("-1")
  71. && (!(response.getMBResp().getSong()).equals("") || !(response
  72. .getMBResp().getSong()).equals("-1"))) {
  73. song = response.getMBResp().getSong();
  74. }
  75. notification.setArtistName(artist);
  76. notification.setSongName(song);
  77. notification.setArtistId(response.getArtistId());
  78. notification.setSongId(response.getMusicId());
  79. notification.setMediaId(response.getMediaId());
  80. notification.setMedia(artist + song);
  81. notification.setTrack(true);
  82. notification.setNotDisplayable();
  83. notification.setStartTime(new Timestamp(0));
  84. notification.setEndTime(new Timestamp(0));
  85. notification.setPath("");
  86. notification.setMusicBrainzArtistId(response.getMusicBrainzArtistId());
  87. notification.setMusicBrainzSongId(response.getMusicBrainzMusicId());
  88. notification.setNotificationType(0);
  89. Notifier.notify(notification);
  90. }
  91. }