author | indvdum (gotoindvdum@gmail.com) |
Wed, 23 Nov 2011 17:52:25 +0300 | |
changeset 16 | 2d6a668325f9 |
parent 5 | src/main/java/ru/indvdum/mywork/MyWork.java@14e23102379e |
permissions | -rw-r--r-- |
indvdum@1 | 1 |
package ru.indvdum.mywork; |
indvdum@1 | 2 |
|
indvdum@1 | 3 |
import java.util.Date; |
indvdum@1 | 4 |
|
indvdum@5 | 5 |
import javax.persistence.EntityManager; |
indvdum@5 | 6 |
import javax.persistence.EntityManagerFactory; |
indvdum@5 | 7 |
import javax.persistence.Persistence; |
indvdum@5 | 8 |
|
indvdum@5 | 9 |
import org.mortbay.component.LifeCycle; |
indvdum@5 | 10 |
import org.mortbay.component.LifeCycle.Listener; |
indvdum@1 | 11 |
import org.mortbay.jetty.Connector; |
indvdum@1 | 12 |
import org.mortbay.jetty.Server; |
indvdum@1 | 13 |
import org.mortbay.jetty.servlet.Context; |
indvdum@1 | 14 |
import org.mortbay.jetty.servlet.ServletHolder; |
indvdum@1 | 15 |
|
indvdum@1 | 16 |
import com.vaadin.terminal.gwt.server.ApplicationServlet; |
indvdum@1 | 17 |
|
indvdum@1 | 18 |
/** |
indvdum@1 | 19 |
* @author indvdum |
indvdum@5 | 20 |
* 12.08.2011 17:31:37 |
indvdum@1 | 21 |
* |
indvdum@1 | 22 |
*/ |
indvdum@1 | 23 |
public class MyWork { |
indvdum@5 | 24 |
public static EntityManagerFactory EMF = null; |
indvdum@5 | 25 |
public static EntityManager EM = null; |
indvdum@1 | 26 |
|
indvdum@1 | 27 |
/** |
indvdum@1 | 28 |
* @param args |
indvdum@1 | 29 |
* @throws Exception |
indvdum@1 | 30 |
*/ |
indvdum@1 | 31 |
public static void main(String[] args) throws Exception { |
indvdum@1 | 32 |
Server server = new Server(); |
indvdum@1 | 33 |
Connector connector = new org.mortbay.jetty.nio.SelectChannelConnector(); |
indvdum@1 | 34 |
connector.setPort(8080); |
indvdum@1 | 35 |
connector.setMaxIdleTime(720000); |
indvdum@1 | 36 |
server.addConnector(connector); |
indvdum@1 | 37 |
|
indvdum@1 | 38 |
Context root = new Context(server, "/", Context.SESSIONS); |
indvdum@1 | 39 |
ServletHolder vaadinServlet = new ServletHolder(new ApplicationServlet()); |
indvdum@1 | 40 |
vaadinServlet.setInitParameter("application", "ru.indvdum.mywork.vaadin.MyWorkApplication"); |
indvdum@1 | 41 |
root.addServlet(vaadinServlet, "/*"); |
indvdum@1 | 42 |
|
indvdum@5 | 43 |
server.addLifeCycleListener(new Listener(){ |
indvdum@5 | 44 |
|
indvdum@5 | 45 |
@Override |
indvdum@5 | 46 |
public void lifeCycleFailure(LifeCycle event, Throwable cause) { |
indvdum@5 | 47 |
|
indvdum@5 | 48 |
} |
indvdum@5 | 49 |
|
indvdum@5 | 50 |
@Override |
indvdum@5 | 51 |
public void lifeCycleStarted(LifeCycle event) { |
indvdum@5 | 52 |
EMF = Persistence.createEntityManagerFactory("mywork"); |
indvdum@5 | 53 |
EM = EMF.createEntityManager(); |
indvdum@5 | 54 |
} |
indvdum@5 | 55 |
|
indvdum@5 | 56 |
@Override |
indvdum@5 | 57 |
public void lifeCycleStarting(LifeCycle event) { |
indvdum@5 | 58 |
|
indvdum@5 | 59 |
} |
indvdum@5 | 60 |
|
indvdum@5 | 61 |
@Override |
indvdum@5 | 62 |
public void lifeCycleStopped(LifeCycle event) { |
indvdum@5 | 63 |
|
indvdum@5 | 64 |
} |
indvdum@5 | 65 |
|
indvdum@5 | 66 |
@Override |
indvdum@5 | 67 |
public void lifeCycleStopping(LifeCycle event) { |
indvdum@5 | 68 |
EM.close(); |
indvdum@5 | 69 |
EMF.close(); |
indvdum@5 | 70 |
} |
indvdum@5 | 71 |
|
indvdum@5 | 72 |
}); |
indvdum@5 | 73 |
|
indvdum@1 | 74 |
server.start(); |
indvdum@1 | 75 |
System.out.println("Jetty server started at " + new Date()); |
indvdum@1 | 76 |
} |
indvdum@1 | 77 |
|
indvdum@1 | 78 |
} |