2

red5 でジョブ スケジューラ用に次の抽象クラスを作成しました。

package com.demogames.jobs;

import com.demogames.demofacebook.MysqlDb;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.scheduling.IScheduledJob;
import org.red5.server.api.so.ISharedObject;
import org.apache.log4j.Logger;
import org.red5.server.api.Red5;

/**
 *
 * @author ufk
 */
abstract public class DemoJob implements IScheduledJob {

protected IConnection conn;
protected IClient client;
protected ISharedObject so;
protected IScope scope;
protected MysqlDb mysqldb;

protected static org.apache.log4j.Logger log = Logger
    .getLogger(DemoJob.class);

protected DemoJob (ISharedObject so, MysqlDb mysqldb){

       this.conn=Red5.getConnectionLocal();
       this.client = conn.getClient();
       this.so=so;
       this.mysqldb=mysqldb;
       this.scope=conn.getScope();
 }

 protected DemoJob(ISharedObject so) {
   this.conn=Red5.getConnectionLocal();
   this.client=this.conn.getClient();
   this.so=so;
   this.scope=conn.getScope();
 }

 protected DemoJob() {
   this.conn=Red5.getConnectionLocal();
   this.client=this.conn.getClient();
   this.scope=conn.getScope();
 }

}

次に、前のものを拡張する単純なクラスを作成しました。

public class StartChallengeJob extends DemoJob {

 public void execute(ISchedulingService service) {

   log.error("test");

 }

}

問題は、メイン アプリケーションがパラメーターなしでコンストラクターしか認識できないことです。new StartChallengeJob() メインアプリケーションがすべてのコンストラクターを認識しないのはなぜですか?

ありがとう!

4

2 に答える 2

8

コンストラクターは継承されません。StartChallengeJobは、事実上次のようになります。

public class StartChallengeJob extends DemoJob {

  public StartChallengeJob() {
    super();
  }

  public void execute(ISchedulingService service) {    
    log.error("test");   
  }    
}

すべてのスーパークラスコンストラクターシグネチャを使用できるようにする場合は、それらのコンストラクターも含める必要がありますStartChallengeJob

public class StartChallengeJob extends DemoJob {

  public DemoJob (ISharedObject so, MysqlDb mysqldb) {
    super(so, mysqldb);
  }

  public DemoJob (ISharedObject so) {
    super(so);
  }

  public StartChallengeJob() {
    super();
  }

  public void execute(ISchedulingService service) {    
    log.error("test");   
  }    
}
于 2010-05-04T09:58:40.113 に答える
4

質問に示されているStartChallengeJobクラスの場合、コンパイラはデフォルトのコンストラクターを生成します。これは、基本クラスのデフォルトのコンストラクターを暗黙的に呼び出します。

この既定の動作が必要でない場合は、1 つまたは複数のコンストラクターを で明示的に定義する必要がありますStartChallengeJob。これにより、目的の基本クラス コンストラクターが呼び出されます。たとえば、デフォルトのコンストラクターとパラメーター化されたコンストラクターの両方が必要な場合は、両方を定義する必要があります。

public class StartChallengeJob extends DemoJob {

 public StartChallengeJob(){
       // implicitly calls the base class default constructor: super();
 }

 public StartChallengeJob (ISharedObject so, MysqlDb mysqldb){
       super(so, mysqldb);
 }

 public void execute(ISchedulingService service) {

   log.error("test");

 }

}
于 2010-05-04T09:54:54.587 に答える