⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jasenscanner.java

📁 spam source codejasen-0.9jASEN - java Anti Spam ENgine.zip 如标题所示
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return scan(mm, message, null);
    }


    /**
     * Scans the given mime message using the already mime-parsed JasenMessage.
     * <p>
     * This implementation allows calling applications to implement their own JasenMessage by passing it to the scan engine.
     * </p>
     * @param mm The MimeMessage to be scanned
     * @param message A pre-parsed JasenMessage
     * @param threshold The thresholds.  If any one plugin yields a result >= threshold, scanning is ceased and the result returned immediately
     * @return The results of the scan as a JasenScanResult
     * @throws JasenException
     * @see JasenScanner#scan(MimeMessage, float)
     */
    public JasenScanResult scan(MimeMessage mm, JasenMessage message, float threshold) throws JasenException {
        return scan(mm, message, threshold, null);
    }    
    

    /**
     * Scans the given message.
     * <p>
     * 	All plugins will execute regardless of the probability (or computed total probability) discovered from any single plugin or combination thereof
     * </p>
     * @param mm The MimeMessage to be scanned
     * @param ignored A list of plugin names which will be ignored during the scan.  May be null
     * @return The results of the scan as a JasenScanResult
     * @throws JasenException
     */
    public JasenScanResult scan(MimeMessage mm, String[] ignored) throws JasenException {
        notifyScan();

        try {
            return jasen.scan(mm, ignored);
        }
        finally {
            notifyScanComplete();
        }
    }


    /**
     * Scans the given message.
	 *  <p>
	 * 		The threshold value indicates the value at which we know the message is spam without continuing
	 * 	</p>
     * If the engine computes this threshold prior to all plugins executing, tests are stopped and the result is
     * returned immediately
     * @param mm The MimeMessage to be scanned
     * @param threshold The marker above which scanning ceases
     * @param ignored A list of plugin names which will be ignored during the scan.  May be null
     * @return The results of the scan as a JasenScanResult
     * @throws JasenException
     * @see JasenScanner#scan(MimeMessage, JasenMessage, float)
     */
    public JasenScanResult scan(MimeMessage mm, float threshold, String[] ignored) throws JasenException {

        notifyScan();

        try {
            return jasen.scan(mm, threshold, ignored);
        }
        finally {
            notifyScanComplete();
        }
    }

    /**
     * Scans the message without a threshold specified
     * @param mm The MimeMessage to be scanned
     * @param message A pre-parsed JasenMessage
     * @param ignored A list of plugin names which will be ignored during the scan.  May be null
     * @return The results of the scan as a JasenScanResult
     * @throws JasenException
     * @see JasenScanner#scan(MimeMessage, JasenMessage, float)
     */
    public JasenScanResult scan(MimeMessage mm, JasenMessage message, String[] ignored) throws JasenException {

        notifyScan();

        try {
            return jasen.scan(mm, message, ignored);
        }
        finally {
            notifyScanComplete();
        }

    }


    /**
     * Scans the given mime message using the already mime-parsed JasenMessage.
     * <p>
     * This implementation allows calling applications to implement their own JasenMessage by passing it to the scan engine.
     * </p>
     * @param mm The MimeMessage to be scanned
     * @param message A pre-parsed JasenMessage
     * @param threshold The thresholds.  If any one plugin yields a result >= threshold, scanning is ceased and the result returned immediately
     * @param ignored A list of plugin names which will be ignored during the scan.  May be null
     * @return The results of the scan as a JasenScanResult
     * @throws JasenException
     * @see JasenScanner#scan(MimeMessage, JasenMessage, float)
     */
    public JasenScanResult scan(MimeMessage mm, JasenMessage message, float threshold, String[] ignored) throws JasenException {

        notifyScan();

        try {
            return jasen.scan(mm, message, threshold, ignored);
        }
        finally {
            notifyScanComplete();
        }
    }

    /**
     * Records the occurrance of a scan
     * @throws JasenException
     */
    public void notifyScan() throws JasenException {

        synchronized(scanlock) {
            if(updating) {
                try {
                    logger.debug("Waiting to execute a scan...");
                    scanlock.wait();
                    logger.debug("Stopped waiting executing scan...");
                } catch (InterruptedException ignore) {}

                if(!initialized) {
                    throw new JasenException("Cannot access the jASEN engine until it has been intialized!");
                }
            }

            scansInProgress++;
            scanlock.notifyAll();
        }

        if(scanListener != null) {
            scanListener.onScanStart();
        }
    }

    /**
     * Records the completion of a scan
     * @throws JasenException
     */
    public void notifyScanComplete() throws JasenException {
        synchronized(scanlock) {
            scansInProgress--;
            scanlock.notifyAll();
        }
        
        if(scanListener != null) {
            scanListener.onScanEnd();
        }        
    }

    /**
     * Called by the AutoUpdateManager if there is an update pending to signal a pause in scanning
     *
     */
    public boolean notifyPendingUpdate(JasenAutoUpdateParcel parcel) {
        
        if((autoUpdateListener != null && autoUpdateListener.onBeforeUpdate())
             || autoUpdateListener == null) {
            logger.debug("Scanner notified of pending update.  Locking scan access...");
            
            synchronized(scanlock) {
                // Signal the intention to update
                updating = true;

                // Now wait for any current scans to complete...
                while(scansInProgress > 0) {
                    try {
                        scanlock.wait();
                    } catch (InterruptedException ignore) {}
                }
                
                scanlock.notifyAll();

                if(autoUpdateListener != null) {
                    return autoUpdateListener.onUpdateStart(new JasenAutoUpdateParcelWrapper(parcel));
                }
                else
                {
                    return true;
                }
            }            
        }
        else if(autoUpdateListener != null) {
            logger.debug("Auto update listener aborted update");
        }

        return false;

    }

    /**
     * Called by the AutoUpdateManager when the update has completed
     * @param report A report of the results of an update
     * @throws JasenException
     */
    public void notifyUpdateComplete(JasenAutoUpdateReport report) throws JasenException {

        synchronized(scanlock) {
            
            boolean restart = report.isEngineRestart();

            if(autoUpdateListener != null) {
                if(autoUpdateListener.onUpdateEnd(report) && report.isEngineRestart()) {
                    restart = true;
                }
            }        
            
            if(restart) {
                restartRequired = true;
                logger.debug("Waking up the restarter");
                restarter.wake();
            }

            updating = false;

            logger.info("Auto update completed successfully" + ((report.isEngineRestart()) ? ", restart pending." : ""));   
            
            // Notify waiting listeners
            if(autoUpdateListener != null) {
                autoUpdateListener.onAfterUpdate();
            }
            
            scanlock.notifyAll();
        }
    }

    
    public void notifyUpdateDownload(long bytes) {
        if(autoUpdateListener != null) {
            autoUpdateListener.onUpdateDownload(bytes);
        }
    }    
    /**
     * Returns true IFF the engine is initialised and ready for scans.
     * @return True if the engine is alive, false otherwise.
     */
    public boolean isAlive() {
        return alive;
    }

    /**
     * Gets the listener registered for scan events if one has been set.
     * @return The current listener, or null if no listener has been set
     */
    public JasenScanListener getScanListener() {
        return scanListener;
    }

    /**
     * Sets the listener which will record scan events.
     * @param scanListener
     */
    public void setScanListener(JasenScanListener scanListener) {
        this.scanListener = scanListener;
    }

    /**
     * Gets the listener registered for auto update events if one has been set.
     * @return The registered listener, or null if no listener has been set
     */
    public JasenAutoUpdateListener getAutoUpdateListener() {
        return autoUpdateListener;
    }

    /**
     * Sets the listener which will record update completion events.
     * @param autoUpdateListener
     */
    public void setAutoUpdateListener(JasenAutoUpdateListener autoUpdateListener) {
        this.autoUpdateListener = autoUpdateListener;
    }


    /**
     * Forces the engine to run an update check
     * @return If true, the force request was received and the engine is checking for
     * updates. If false, the engine is either not running, or is already in the process of checking
     * @throws JasenException
     */
    public boolean forceUpdate() throws JasenException {
       return JasenAutoUpdateManager.getInstance().forceUpdate();
    }
    
    /**
     * Returns a read-only list of the plugins registered in the engine.
     * <br/>
     * The list does not allow modification.  Any attempt to modify the list will 
     * result in an UnsupportedOperationException
     * @return A list of PluginContainer objects containing the registered plugins
     * @see org.jasen.core.PluginContainer
     */
    public List getPlugins() {
        return new ReadOnlyList(jasen.getPlugins());
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -