📄 autoupdate.java
字号:
/*
* @(#)AutoUpdate.java 7/01/2005
*
* Copyright (c) 2005 jASEN.org
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* 3. The names of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* 4. Any modification or additions to the software must be contributed back
* to the project.
*
* 5. Any investigation or reverse engineering of source code or binary to
* enable emails to bypass the filters, and hence inflict spam and or viruses
* onto users who use or do not use jASEN could subject the perpetrator to
* criminal and or civil liability.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JASEN.ORG,
* OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package org.jasen.samples;
import org.apache.log4j.Logger;
import org.jasen.JasenScanner;
import org.jasen.event.JasenAutoUpdateListener;
import org.jasen.update.JasenAutoUpdateParcelWrapper;
import org.jasen.update.JasenAutoUpdateReport;
/**
* <P>
* Initialises the engine and immediately requests an auto update.
* </P>
* <p>
* This class is for TESTING ONLY
* </p>
* @author Jason Polites
*/
public class AutoUpdate {
public static final Object lock = new Object();
static final Logger logger = Logger.getLogger(AutoUpdate.class);
/**
* <p>
* Just a sample listener
* </p>
*/
static final class UpdateListener extends JasenAutoUpdateListener {
/*
* (non-Javadoc)
* @see org.jasen.event.JasenAutoUpdateListener#onBeforeUpdate()
*/
public boolean onBeforeUpdate() {
logger.debug("Update signalled");
return true;
}
/*
* (non-Javadoc)
* @see org.jasen.event.JasenAutoUpdateListener#onUpdateStart(org.jasen.update.JasenAutoUpdateParcelWrapper)
*/
public boolean onUpdateStart(JasenAutoUpdateParcelWrapper parcel) {
logger.debug("Update commenced");
return true;
}
/*
* (non-Javadoc)
* @see org.jasen.event.JasenAutoUpdateListener#onUpdateEnd(org.jasen.update.JasenAutoUpdateReport)
*/
public boolean onUpdateEnd(JasenAutoUpdateReport report) {
logger.debug("Update finished");
return true;
}
/*
* (non-Javadoc)
* @see org.jasen.event.JasenAutoUpdateListener#onUpdateDownload(long)
*/
public void onUpdateDownload(long bytes) {
logger.debug("Downloaded " + bytes + " bytes");
}
/*
* (non-Javadoc)
* @see org.jasen.event.JasenAutoUpdateListener#onAfterUpdate()
*/
public boolean onAfterUpdate() {
synchronized(lock) {
lock.notify();
}
return true;
}
}
public static void main(String[] args) {
try {
synchronized (lock) {
JasenScanner.getInstance().init();
JasenScanner.getInstance().setAutoUpdateListener(new UpdateListener());
logger.debug("Requesting update...");
JasenScanner.getInstance().forceUpdate();
logger.debug("Update requested, waiting for notification of completion...");
// Wait for the update to complete...
lock.wait();
// We are going to put a wait in here just to give the engine time to restart
// Usually this would not be required (and isn't really required here) but it
// just makes things a little easier to understand
logger.debug("Waiting for engine to restart... (DEBUG ONLY)");
Thread.sleep(5000);
logger.debug("Finished");
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
JasenScanner.getInstance().destroy();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -