Search in sources :

Example 1 with Stopwatch

use of org.nutz.lang.Stopwatch in project nutzboot by nutzam.

the class NbApp method execute.

public boolean execute() {
    Stopwatch sw = Stopwatch.begin();
    try {
        // 各种预备操作
        listener.whenPrepare(this, EventType.before);
        this.prepare();
        listener.whenPrepare(this, EventType.after);
        // 依次启动
        listener.whenInitAppContext(this, EventType.before);
        ctx.init();
        listener.whenInitAppContext(this, EventType.after);
        listener.whenStartServers(this, EventType.before);
        ctx.startServers();
        listener.whenStartServers(this, EventType.after);
        if (ctx.getMainClass().getAnnotation(IocBean.class) != null)
            ctx.getIoc().get(ctx.getMainClass());
        listener.afterAppStated(this);
        sw.stop();
        log.infof("%s started : %sms", ctx.getConf().get("nutz.application.name", "NB"), sw.du());
        started = true;
        return true;
    } catch (Throwable e) {
        log.error("something happen!!", e);
        return false;
    }
}
Also used : Stopwatch(org.nutz.lang.Stopwatch) IocBean(org.nutz.ioc.loader.annotation.IocBean)

Example 2 with Stopwatch

use of org.nutz.lang.Stopwatch in project nutzboot by nutzam.

the class NbMvcLoading method depose.

public void depose(NutConfig config) {
    if (log.isInfoEnabled())
        log.infof("Nutz.Mvc[%s] is deposing ...", config.getAppName());
    Stopwatch sw = Stopwatch.begin();
    // Firstly, upload the user customized desctroy
    try {
        Setup setup = config.getAttributeAs(Setup.class, Setup.class.getName());
        if (null != setup)
            setup.destroy(config);
    } catch (Exception e) {
        throw new LoadingException(e);
    }
    // Done, print info
    sw.stop();
    if (log.isInfoEnabled())
        log.infof("Nutz.Mvc[%s] is down in %sms", config.getAppName(), sw.getDuration());
}
Also used : Stopwatch(org.nutz.lang.Stopwatch) LoadingException(org.nutz.mvc.LoadingException) Setup(org.nutz.mvc.Setup) LoadingException(org.nutz.mvc.LoadingException)

Example 3 with Stopwatch

use of org.nutz.lang.Stopwatch in project nutz by nutzam.

the class NutLoading method depose.

public void depose(NutConfig config) {
    if (log.isInfoEnabled())
        log.infof("Nutz.Mvc[%s] is deposing ...", config.getAppName());
    Stopwatch sw = Stopwatch.begin();
    // Firstly, upload the user customized desctroy
    try {
        Setup setup = config.getAttributeAs(Setup.class, Setup.class.getName());
        if (null != setup)
            setup.destroy(config);
    } catch (Exception e) {
        throw new LoadingException(e);
    } finally {
        SessionProvider sp = config.getSessionProvider();
        if (sp != null)
            sp.notifyStop();
        // If the application has Ioc, depose it
        Ioc ioc = config.getIoc();
        if (null != ioc)
            ioc.depose();
    }
    // Done, print info
    sw.stop();
    if (log.isInfoEnabled())
        log.infof("Nutz.Mvc[%s] is down in %sms", config.getAppName(), sw.getDuration());
}
Also used : Stopwatch(org.nutz.lang.Stopwatch) Ioc(org.nutz.ioc.Ioc)

Example 4 with Stopwatch

use of org.nutz.lang.Stopwatch in project nutz by nutzam.

the class UploadingSpeedTest method main.

public static void main(String[] args) {
    if (0 == args.length) {
        System.err.println("Lack files directory!");
        System.exit(0);
    }
    File dir = Files.findFile(args[0]);
    if (null == dir) {
        System.err.println("Fail to found directory: " + args[0]);
        System.exit(0);
    }
    final Uploading up = UploadUnit.TYPE.born();
    final UploadingContext uc = UploadingContext.create("~/nutz/unit/uploadtmp");
    File[] files = dir.listFiles();
    final MockHttpServletRequest req = request().setInputStream(insmulti("UTF-8", files));
    req.setSession(session(context()));
    req.init();
    Object monLock = new Object();
    int monInterval = 2000;
    UploadMonitor mon = new UploadMonitor(monLock, req.getSession(), out, monInterval);
    Thread monThread = new Thread(mon, "UploadingMonitor");
    monThread.start();
    out.println("Begin...");
    Stopwatch sw = null;
    try {
        sw = Stopwatch.run(new Atom() {

            public void run() {
                try {
                    up.parse(req, uc);
                } catch (UploadException e) {
                    throw Lang.wrapThrow(e);
                }
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        mon.stop();
        out.println("\n...Done!");
        if (null != sw)
            out.println(sw);
    }
}
Also used : MockHttpServletRequest(org.nutz.mock.servlet.MockHttpServletRequest) Stopwatch(org.nutz.lang.Stopwatch) Atom(org.nutz.trans.Atom) File(java.io.File)

Example 5 with Stopwatch

use of org.nutz.lang.Stopwatch in project nutz by nutzam.

the class FastClassFactoryTest method testInvokeObjectMethodObjectArray.

@Test
public void testInvokeObjectMethodObjectArray() throws Throwable {
    DefaultClassDefiner.debugDir = Disks.normalize("~/nutz_fastclass/");
    FastMethod fc = FastMethodFactory.make(Pet.class.getConstructor());
    fc = FastMethodFactory.make(Pet.class.getConstructor());
    // net.sf.cglib.reflect.FastClass fc2 = net.sf.cglib.reflect.FastClass.create(Pet.class);
    Mirror<Pet> mirror = Mirror.me(Pet.class);
    Borning<Pet> mb = mirror.getBorning();
    for (int i = 0; i < 10000; i++) {
        if (null == fc.invoke(null))
            throw new RuntimeException();
    }
    for (int i = 0; i < 10000; i++) {
        new Pet();
    }
    for (int i = 0; i < 10000; i++) {
        mb.born();
    }
    // for (int i = 0; i < 10000; i++) {
    // fc2.newInstance();
    // }
    System.gc();
    Lang.quiteSleep(1000);
    System.gc();
    Pet pet = null;
    Stopwatch sw = Stopwatch.begin();
    for (int i = 0; i < 1000000; i++) {
        pet = new Pet();
    }
    sw.stop();
    System.out.println("Native New    :" + sw);
    System.gc();
    Lang.quiteSleep(1000);
    System.gc();
    sw = Stopwatch.begin();
    for (int i = 0; i < 1000000; i++) {
        pet = (Pet) fc.invoke(null);
    }
    sw.stop();
    System.out.println("FastClass born:" + sw);
    System.gc();
    Lang.quiteSleep(1000);
    System.gc();
    sw = Stopwatch.begin();
    for (int i = 0; i < 1000000; i++) {
        pet = mb.born();
    }
    sw.stop();
    System.out.println("mirror born   :" + sw);
    System.gc();
    Lang.quiteSleep(1000);
    System.gc();
    sw = Stopwatch.begin();
    for (int i = 0; i < 1000000; i++) {
        new Object();
    }
    sw.stop();
    System.out.println("NULL          :" + sw);
    System.gc();
    Lang.quiteSleep(1000);
    System.gc();
    // System.gc();
    if (pet != null)
        System.out.println(FastClassFactory.get(Pet.class.getMethod("hashCode")).invoke(pet));
}
Also used : Stopwatch(org.nutz.lang.Stopwatch) Pet(org.nutz.dao.test.meta.Pet) Test(org.junit.Test)

Aggregations

Stopwatch (org.nutz.lang.Stopwatch)14 Test (org.junit.Test)4 File (java.io.File)3 Pet (org.nutz.dao.test.meta.Pet)3 Atom (org.nutz.trans.Atom)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 Issue1163Pet (org.nutz.dao.test.meta.issue1163.Issue1163Pet)2 AbcPet (org.nutz.dao.test.meta.nutzcn.AbcPet)2 Ioc (org.nutz.ioc.Ioc)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Ignore (org.junit.Ignore)1 Cnd (org.nutz.dao.Cnd)1 NutDao (org.nutz.dao.impl.NutDao)1