Package de.sosd.mediaserver.task

Source Code of de.sosd.mediaserver.task.ApplicationShutdownTasks

package de.sosd.mediaserver.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import de.sosd.mediaserver.dao.SystemDao;
import de.sosd.mediaserver.domain.db.SystemDomain;
import de.sosd.mediaserver.service.MediaserverConfiguration;
import de.sosd.mediaserver.service.dlna.UPNPNetwork;

@Service
public class ApplicationShutdownTasks implements ApplicationListener<ContextClosedEvent> {

  @Autowired
  private SystemDao systemDao;
 
  @Autowired
  private UPNPNetwork upnp;
 
  @Autowired
  private MediaserverConfiguration cfg;
 
  @Override
  public void onApplicationEvent(final ContextClosedEvent event) {
    setSystemOffline();
  }
 

  @Transactional(propagation=Propagation.REQUIRED)
  private void setSystemOffline() {
    this.upnp.sendByeBye();
    this.upnp.stopListening();
    final SystemDomain system = this.systemDao.getSystem(cfg.getUSN());
    system.setOnline(false);
    this.systemDao.store(system);
  }

}
TOP

Related Classes of de.sosd.mediaserver.task.ApplicationShutdownTasks

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.