Package org.jmule.core.jkad.utils.timer

Examples of org.jmule.core.jkad.utils.timer.Task


        removeSourceTask(task.getPublishID());
      }
     
    };
   
    publisher_maintenance = new Task() {
      public void run() {
        /*for(PublishKeywordTask task : keywordTasks.values()){
          if (Lookup.getSingleton().getLookupLoad()>INDEXTER_MAX_LOAD_TO_NOT_PUBLISH) return ;
          long currentTime = System.currentTimeMillis();
          if (currentTime - task.getLastpublishTime() >= task.getPublishInterval()) {
View Full Code Here


    }
    Logger.getSingleton().logMessage("Loaded notes : " + notes.size());
    Logger.getSingleton().logMessage("Loaded keywords : " + keywords.size());
    Logger.getSingleton().logMessage("Loaded sources : " + sources.size());
   
    save_data_task = new Task() {
      public void run() {
        synchronized (notes) {
          try {
            SrcIndexDat.writeFile(NOTE_INDEX_DAT, notes);
          } catch (Throwable e) {
            Logger.getSingleton().logException(e);
            e.printStackTrace();
          }
        }
       
        synchronized (keywords) {
          try {
            SrcIndexDat.writeFile(KEY_INDEX_DAT, keywords);
          } catch (Throwable e) {
            Logger.getSingleton().logException(e);
            e.printStackTrace();
          }
        }
        synchronized (sources) {
          try {
              SrcIndexDat.writeFile(SRC_INDEX_DAT, sources);
          } catch (Throwable e) {
            Logger.getSingleton().logException(e);
            e.printStackTrace();
          }
        }
      }
    };
   
    Timer.getSingleton().addTask(INDEXER_SAVE_DATA_INTERVAL, save_data_task, true);
   
    cleaner_task = new Task() {
      public void run() {
        synchronized (notes) {
          for(Int128 id : notes.keySet()) {
            Index index = notes.get(id);
            index.removeContactsWithTimeOut(JKadConstants.TIME_24_HOURS);
View Full Code Here

  }
 
  private RoutingTable() {
    root = new Node(null, new Int128(), 0, new KBucket());
   
    maintenanceTask = new Task() {
      private LookupTask lookup_new_contacts = null;
      public void run() {
        if (getTotalContacts() < ROUTING_TABLE_DIFICIT_CONTACTS) {
          if ((lookup_new_contacts == null)||(!lookup_new_contacts.isLookupStarted())) {
           
            Int128 fake_target = new Int128(Utils.getRandomInt128());
            lookup_new_contacts = new LookupTask(RequestType.FIND_NODE, fake_target, JKadConstants.toleranceZone) {
              public void lookupTimeout() {
              }

              public void stopLookupEvent() {
              }
             
              public void processToleranceContacts(
                  ContactAddress sender,
                  List<KadContact> results) {
                for(KadContact contact : results) {
                  addContact(contact);
                }
               
                if (getTotalContacts() > ROUTING_TABLE_DIFICIT_CONTACTS_STOP) {
                  Lookup.getSingleton().removeLookupTask(targetID);
                }
              }
             
            };
            Lookup.getSingleton().addLookupTask(lookup_new_contacts);
          }
        }
             
        for(MaintenanceContact maintenance_contact : maintenanceContacts.values()) {
          KadContact contact = maintenance_contact.kadContact;
         
          long contact_time = System.currentTimeMillis() - contact.getLastResponse();
          if (contact_time >= ROUTING_TABLE_CONTACT_TIMEOUT) {
            int rcount = maintenance_contact.requestCount;
            if (rcount<=contact.getContactType().toByte()+1) {
              KadPacket hello_packet;
              try {
                hello_packet = PacketFactory.getHello2ReqPacket(TagList.EMPTY_TAG_LIST);
                _network_manager.sendKadPacket(hello_packet, maintenance_contact.kadContact.getIPAddress(), maintenance_contact.kadContact.getUDPPort());
              } catch (JMException e) {
                e.printStackTrace();
              }

              maintenance_contact.requestCount++;
              continue;
            }
           
            int beta = maintenance_contact.requestCount - maintenance_contact.responseCount;
            boolean downgrate = false;
            if (beta>contact.getContactType().toByte()+1)
              downgrate = true;
           
            if (downgrate) {
              if (contact.getContactType() == ContactType.ScheduledForRemoval) {
                maintenanceContacts.remove(contact.getContactAddress());
                removeNode(contact);
                continue;
              }
              contact.downgrateType();
              notifyContactUpdated(contact);
              if (contact.getContactType()!=ContactType.ScheduledForRemoval)
                maintenanceContacts.remove(contact.getContactAddress());
              continue;
            }
            maintenanceContacts.remove(contact.getContactAddress());
            continue;
          }
         
        }
        if (maintenanceContacts.size()>=ROUTING_TABLE_MAX_MAINTENANCE_CONTACTS) return ;
        List<KadContact> candidatList = getContactsWithTimeout(ROUTING_TABLE_CONTACT_IGNORE_TIME);
        if (candidatList.size() == 0) return ;
        for(int i = 0;i<ROUTING_TABLE_MAINTENANCE_CONTACTS; i++) {
          KadContact addContact = null;
          do {
            int id = Utils.getRandom(candidatList.size());
            addContact = candidatList.get(id);
           
          }while(maintenanceContacts.containsKey(addContact.getContactAddress()));
          MaintenanceContact c = new MaintenanceContact(addContact);
          maintenanceContacts.put(addContact.getContactAddress(), c);
         
          KadPacket hello_packet;
          try {
            hello_packet = PacketFactory.getHello2ReqPacket(TagList.EMPTY_TAG_LIST);
            _network_manager.sendKadPacket(hello_packet, addContact.getIPAddress(), addContact.getUDPPort());
          } catch (JMException e) {
            e.printStackTrace();
          }
          c.requestCount++;
        }
      }
     
    };
   
    routingTableSave = new Task() {
      public void run() {
        storeContacts();
      }     
    };

    contact_checker = new Task() {
      public void run() {
        for(KadContact contact : tree_nodes) {
          long contact_time = System.currentTimeMillis() - contact.getLastResponse();
          if (contact_time >  Active2MoreHours.timeRequired()) {
            if (contact.getContactType()==Active2MoreHours) continue;
View Full Code Here

        }
       
      }
    }
   
    bootStrapTask = new Task() {
      public void run() {
        if (bootStrapResponses >= BOOTSTRAP_STOP_CONTACTS) {
          completeBootStrap();
          return ;
        }
View Full Code Here

        e.printStackTrace();
      }
    }

    filesToPublishChecker = new Task() {
      Set<FileHash> publishedFiles = new HashSet<FileHash>();

      public void run() {
        if (getStatus() != JKadStatus.CONNECTED) return;
        SharingManager sharing_manager = SharingManagerSingleton
View Full Code Here

      singleton = new Lookup();
    return singleton;
  }
 
  private Lookup() {
    lookupCleaner  = new Task() {
      public void run() {
        runNextTask();
        for(Int128 key : lookupTasks.keySet()) {
          LookupTask task = lookupTasks.get(key);
          if ((System.currentTimeMillis() - task.getResponseTime() > task.getTimeOut())
View Full Code Here

      KadContact contact = getNearestContact(Utils.XOR(targetID,_jkad_manager.getClientID()), possibleContacts,usedContacts);
     
      lookupContact(contact);
    }
   
    contactCleaner = new Task() {
      public void run() {
        for(ContactAddress address : requestedContacts.keySet()) {
          RequestedContact c = requestedContacts.get(address);
          if (c==null) { requestedContacts.remove(address); continue; }
          if (System.currentTimeMillis() - c.getRequestTime() > LOOKUP_CONTACT_TIMEOUT) {
View Full Code Here

    return singleton;
  }

  private FirewallChecker() {
    routing_table = RoutingTable.getSingleton();
    firewall_check_task = new Task() {
      public void run() {
        if (!_jkad_manager.isConnected()) {
          return;
        }
        List<KadContact> list = routing_table
View Full Code Here

TOP

Related Classes of org.jmule.core.jkad.utils.timer.Task

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.