updatecertificate.java

来自「一个agent 工具包,可以开发移动设备应用,考虑了安全措施」· Java 代码 · 共 85 行

JAVA
85
字号
package SOMA.security.infrastructure.updatePolicy;


import java.io.PrintStream;

import SOMA.network.connection.Daemon;
import SOMA.security.infrastructure.Infrastructure;


public class UpdateCertificate implements Runnable, Daemon
{
  Thread myServerDaemon;
  private Object status = OFF;

  private UpdatePolicy policy;
  private Infrastructure pki;
  private PrintStream out;


  public UpdateCertificate ( UpdatePolicy policy , Infrastructure pki , PrintStream out )
  {
    this.policy = policy;
    this.pki = pki;
    this.out = out;
  }

    /** Avvio del demone. */
  public synchronized void start()
      throws PolicyException
  {
    if( status != ON )
    {
      myServerDaemon = new Thread( this, toString() );
      status = ON;
      myServerDaemon.start();
    }
    else throw new PolicyException( "Server already ON" );
  }



  /** Arresto del demone. */
  public void stop()
        throws PolicyException
  {
    if( status != OFF ) status = OFF;
    else throw new PolicyException( "Server already OFF" );
  }

  public Object getStatus()
  {
    return status;
  }

  public String toString()
  {
     return "<UpdateCertificate: status = " + status + "\n  Policy = " + policy + ">";
  }

  /** Metodo eseguito dal demone: attende richieste ed attiva connessioni finche' lo stato rimane ON e la ServerSocket attiva. */
  public void run()
  {

    while( status == ON )
    {
      try{

        if ( this.policy.update() )

          if ( pki.getInfrastructureAddress().onLine )
          {
            out.println("Updating certificate into local list.");
            long t0 = System.currentTimeMillis();
            pki.updateCertificateCRLList();
            long t1 = System.currentTimeMillis();
            out.println("Update certificate into local list t = " + (t1 - t0) + " ms");
          }
          Thread.sleep( this.policy.getSleepTime() );
      } catch ( Exception e ) { out.println( "Certificate update error." ); }

    }
  }


}

⌨️ 快捷键说明

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