1b0dff94a530d78d9d32079c1c9a5208b49312d0
[portal/sdk.git] /
1 package org.onap.portalapp.music.conf;
2
3 import java.util.Map;
4 import java.util.concurrent.ConcurrentHashMap;
5
6 import org.onap.music.eelf.logging.EELFLoggerDelegate;
7 import org.onap.music.exceptions.MusicLockingException;
8 import org.onap.music.exceptions.MusicServiceException;
9 import org.onap.portalapp.music.service.MusicService;
10 import org.onap.portalapp.music.util.MusicUtil;
11 import org.springframework.session.Session;
12
13 public class MusicSessionRepositoryHandler {
14         
15         private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicSessionRepositoryHandler.class);
16         private final Map<String, Session> sessions = new ConcurrentHashMap<>();
17         private boolean musicCache = MusicUtil.isCached();
18         
19         
20         public Session get(String id) {
21                 if(!musicCache){
22                         try {
23                                 Session session = MusicService.getMetaAttribute(id);
24                                 return session;
25                         } catch (Exception e) {
26                                 logger.error(EELFLoggerDelegate.errorLogger, "get failed with id " + id, e);
27                         }
28                 }
29                 return this.sessions.get(id);
30         }
31
32
33
34         public void remove(String id) {
35                  sessions.remove(id);
36                  try {
37                         MusicService.removeSession(id);
38                 } catch (MusicLockingException e) {
39                         logger.error(EELFLoggerDelegate.errorLogger, "removeSession locking failed with id " + id, e);
40                 } catch (MusicServiceException e) {
41                         logger.error(EELFLoggerDelegate.errorLogger, "removeSession failed with id " + id, e);
42                 }
43         }
44
45
46
47         public void put(String id, MusicSession musicSession) {
48                 sessions.put(id, musicSession);
49                 try {
50                         MusicService.setMetaAttribute(musicSession);
51                 } catch (Exception e) {
52                         logger.error(EELFLoggerDelegate.errorLogger, "setMetaAttribute failed with id " + id, e);
53                 }
54         }
55
56 }