FileDocCategorySizeDatePackage
DHTView.javaAPI DocAzureus 3.0.3.422935Sun Aug 12 22:16:16 BST 2007org.gudy.azureus2.ui.swt.views.stats

DHTView

public class DHTView extends org.gudy.azureus2.ui.swt.views.AbstractIView

Fields Summary
public static final int
DHT_TYPE_MAIN
public static final int
DHT_TYPE_CVS
public static final int
DHT_TYPE_MAIN_V6
com.aelitis.azureus.core.dht.DHT
dht
org.eclipse.swt.widgets.Composite
panel
String
yes_str
String
no_str
org.eclipse.swt.widgets.Label
lblUpTime
org.eclipse.swt.widgets.Label
lblNumberOfUsers
org.eclipse.swt.widgets.Label
lblNodes
org.eclipse.swt.widgets.Label
lblLeaves
org.eclipse.swt.widgets.Label
lblContacts
org.eclipse.swt.widgets.Label
lblReplacements
org.eclipse.swt.widgets.Label
lblLive
org.eclipse.swt.widgets.Label
lblUnknown
org.eclipse.swt.widgets.Label
lblDying
org.eclipse.swt.widgets.Label
lblRendezvous
org.eclipse.swt.widgets.Label
lblReachable
org.eclipse.swt.widgets.Label
lblKeys
org.eclipse.swt.widgets.Label
lblValues
org.eclipse.swt.widgets.Label
lblLocal
org.eclipse.swt.widgets.Label
lblDirect
org.eclipse.swt.widgets.Label
lblIndirect
org.eclipse.swt.widgets.Label
lblDivFreq
org.eclipse.swt.widgets.Label
lblDivSize
org.eclipse.swt.widgets.Label
lblReceivedPackets
org.eclipse.swt.widgets.Label
lblReceivedBytes
org.eclipse.swt.widgets.Label
lblSentPackets
org.eclipse.swt.widgets.Label
lblSentBytes
org.eclipse.swt.widgets.Label[]
lblPings
org.eclipse.swt.widgets.Label[]
lblFindNodes
org.eclipse.swt.widgets.Label[]
lblFindValues
org.eclipse.swt.widgets.Label[]
lblStores
org.eclipse.swt.widgets.Label[]
lblData
org.eclipse.swt.widgets.Canvas
in
org.eclipse.swt.widgets.Canvas
out
org.gudy.azureus2.ui.swt.components.graphics.SpeedGraphic
inGraph
org.gudy.azureus2.ui.swt.components.graphics.SpeedGraphic
outGraph
boolean
activityChanged
com.aelitis.azureus.core.dht.control.DHTControlListener
controlListener
org.eclipse.swt.widgets.Table
activityTable
com.aelitis.azureus.core.dht.control.DHTControlActivity[]
activities
private final int
dht_type
private int
refreshIter
Constructors Summary
public DHTView(int dht_type)

  

       
    this.dht_type = dht_type;
    init();
  
Methods Summary
public voiddelete()

    Utils.disposeComposite(panel);
    if (dht != null) {
      dht.getControl().removeListener(controlListener);
    }
    outGraph.dispose();
    inGraph.dispose();
  
public org.eclipse.swt.widgets.CompositegetComposite()

    return panel;
  
public java.lang.StringgetData()

	  return( getFullTitle());
  
public java.lang.StringgetFullTitle()

	  if ( dht_type == DHT_TYPE_MAIN ){

		  return( "DHTView.title.full" );

	  }else if ( dht_type == DHT_TYPE_CVS ){

		  return( "DHTView.title.fullcvs" );
	  }else{

		  return( "DHTView.title.full_v6" );
	  }
  
private voidinit()

    try {
      PluginInterface dht_pi = AzureusCoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass( DHTPlugin.class );
        
      if ( dht_pi == null ){
      	   
    	  return;
      }
         
      DHT[] dhts = ((DHTPlugin)dht_pi.getPlugin()).getDHTs();
      
      for (int i=0;i<dhts.length;i++){
    	  if ( dhts[i].getTransport().getNetwork() == dht_type ){
    		  dht = dhts[i];
    		  break;
    	  }
      }
	  
      if ( dht == null ){
    	  
    	  return;
      }
      
      controlListener = new DHTControlListener() {
        public void activityChanged(DHTControlActivity activity,int type) {
          activityChanged = true;
        }                
      };
      dht.getControl().addListener(controlListener);
      
    } catch(Exception e) {
      Debug.printStackTrace( e );
    }
  
private voidinitialiseActivityGroup()

    Group gActivity = new Group(panel,SWT.NONE);
    Messages.setLanguageText(gActivity,"DHTView.activity.title");
    gActivity.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
    gActivity.setLayout(new GridLayout());
    
    activityTable = new Table(gActivity,SWT.VIRTUAL | SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
    activityTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    
    final TableColumn colStatus =  new TableColumn(activityTable,SWT.LEFT);
    Messages.setLanguageText(colStatus,"DHTView.activity.status");
    colStatus.setWidth(80);
    
    final TableColumn colType =  new TableColumn(activityTable,SWT.LEFT);
    Messages.setLanguageText(colType,"DHTView.activity.type");
    colType.setWidth(80);
    
    final TableColumn colName =  new TableColumn(activityTable,SWT.LEFT);
    Messages.setLanguageText(colName,"DHTView.activity.target");
    colName.setWidth(80);
    
    final TableColumn colDetails =  new TableColumn(activityTable,SWT.LEFT);
    Messages.setLanguageText(colDetails,"DHTView.activity.details");
    colDetails.setWidth(300);
    colDetails.setResizable(false);
    
    
    activityTable.setHeaderVisible(true);
    Listener computeLastRowWidthListener = new Listener() {
      public void handleEvent(Event event) {
        if(activityTable == null || activityTable.isDisposed()) return;
        int totalWidth = activityTable.getClientArea().width;
        int remainingWidth = totalWidth 
                               - colStatus.getWidth()
                               - colType.getWidth()
                               - colName.getWidth();
        if(remainingWidth > 0)
          colDetails.setWidth(remainingWidth);
      }
    };
    activityTable.addListener(SWT.Resize, computeLastRowWidthListener);    
    colStatus.addListener(SWT.Resize,computeLastRowWidthListener);
    colType.addListener(SWT.Resize,computeLastRowWidthListener);
    colName.addListener(SWT.Resize,computeLastRowWidthListener);
    
    activityTable.addListener(SWT.SetData, new Listener() {
      public void handleEvent(Event event) {
        TableItem item = (TableItem) event.item;
        int index = activityTable.indexOf (item);
        item.setText (0,MessageText.getString("DHTView.activity.status." + activities[index].isQueued()));
        item.setText (1,MessageText.getString("DHTView.activity.type." + activities[index].getType()));
        item.setText (2,ByteFormatter.nicePrint(activities[index].getTarget()));
        item.setText (3,activities[index].getDescription());
      }
    });
    
  
private voidinitialiseDBGroup()

    Group gDB = new Group(panel,SWT.NONE);
    Messages.setLanguageText(gDB,"DHTView.db.title");
    
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.verticalAlignment = SWT.FILL;
    gDB.setLayoutData(data);
    
    GridLayout layout = new GridLayout();
    layout.numColumns = 6;    
    layout.makeColumnsEqualWidth = true;
    gDB.setLayout(layout);
    
    Label label = new Label(gDB,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.db.keys");    
    
    lblKeys = new Label(gDB,SWT.NONE);
    lblKeys.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gDB,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.db.values");    
    
    lblValues = new Label(gDB,SWT.NONE);
    lblValues.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gDB,SWT.NONE);
    label = new Label(gDB,SWT.NONE);
    
    
    label = new Label(gDB,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.db.local");    
    
    lblLocal = new Label(gDB,SWT.NONE);
    lblLocal.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gDB,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.db.direct");    
    
    lblDirect = new Label(gDB,SWT.NONE);
    lblDirect.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gDB,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.db.indirect");    
    
    lblIndirect = new Label(gDB,SWT.NONE);
    lblIndirect.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false)); 
    
    
    label = new Label(gDB,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.db.divfreq");    
    
    lblDivFreq = new Label(gDB,SWT.NONE);
    lblDivFreq.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gDB,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.db.divsize");    
    
    lblDivSize = new Label(gDB,SWT.NONE);
    lblDivSize.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
  
private voidinitialiseGeneralGroup()

    Group gGeneral = new Group(panel,SWT.NONE);
    Messages.setLanguageText(gGeneral, "DHTView.general.title" );
    
    GridData data = new GridData();
    data.verticalAlignment = SWT.BEGINNING;
    data.widthHint = 350;
    gGeneral.setLayoutData(data);
    
    GridLayout layout = new GridLayout();
    layout.numColumns = 6;
    gGeneral.setLayout(layout);
    
    
    Label label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.uptime");    
    
    lblUpTime = new Label(gGeneral,SWT.NONE);
    lblUpTime.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.users");    
    
    lblNumberOfUsers = new Label(gGeneral,SWT.NONE);
    lblNumberOfUsers.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.reachable");    

    lblReachable = new Label(gGeneral,SWT.NONE);
    lblReachable.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.nodes");    
    
    lblNodes = new Label(gGeneral,SWT.NONE);
    lblNodes.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.leaves");    
    
    lblLeaves = new Label(gGeneral,SWT.NONE);
    lblLeaves.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.rendezvous");    

    lblRendezvous = new Label(gGeneral,SWT.NONE);
    lblRendezvous.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.contacts");    
    
    lblContacts = new Label(gGeneral,SWT.NONE);
    lblContacts.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.replacements");    
    
    lblReplacements = new Label(gGeneral,SWT.NONE);
    lblReplacements.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.live");    
    
    lblLive= new Label(gGeneral,SWT.NONE);
    lblLive.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    label = new Label(gGeneral,SWT.NONE);
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.unknown");    
    
    lblUnknown = new Label(gGeneral,SWT.NONE);
    lblUnknown.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gGeneral,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.general.dying");    
    
    lblDying = new Label(gGeneral,SWT.NONE);
    lblDying.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));    
  
private voidinitialiseOperationDetailsGroup()

    Group gOperations = new Group(panel,SWT.NONE);
    Messages.setLanguageText(gOperations,"DHTView.operations.title");
    gOperations.setLayoutData(new GridData(SWT.FILL,SWT.BEGINNING,true,false));
    
    GridLayout layout = new GridLayout();
    layout.numColumns = 5;
    layout.makeColumnsEqualWidth = true;
    gOperations.setLayout(layout);
    
    
    Label label = new Label(gOperations,SWT.NONE);
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.sent");
    label.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.ok");
    label.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.failed");
    label.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.received");
    label.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.ping");
    
    for(int i = 0 ; i < 4 ; i++) {
      lblPings[i] = new Label(gOperations,SWT.NONE);      
      lblPings[i].setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    }
    
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.findNode");
    
    for(int i = 0 ; i < 4 ; i++) {
      lblFindNodes[i] = new Label(gOperations,SWT.NONE);      
      lblFindNodes[i].setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    }
    
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.findValue");
    
    for(int i = 0 ; i < 4 ; i++) {
      lblFindValues[i] = new Label(gOperations,SWT.NONE);      
      lblFindValues[i].setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    }
    
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.store");
    
    for(int i = 0 ; i < 4 ; i++) {
      lblStores[i] = new Label(gOperations,SWT.NONE);      
      lblStores[i].setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    }
    
    label = new Label(gOperations,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.operations.data");
    
    for(int i = 0 ; i < 4 ; i++) {
      lblData[i] = new Label(gOperations,SWT.NONE);      
      lblData[i].setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    }
  
private voidinitialiseTransportDetailsGroup()

    Group gTransport = new Group(panel,SWT.NONE);
    Messages.setLanguageText(gTransport,"DHTView.transport.title");
    
    GridData data = new GridData(GridData.FILL_VERTICAL);
    data.widthHint = 350;
    data.verticalSpan = 2;
    gTransport.setLayoutData(data);
    
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;    
    layout.makeColumnsEqualWidth = true;
    gTransport.setLayout(layout);
    
    
    Label label = new Label(gTransport,SWT.NONE);
    
    label = new Label(gTransport,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.transport.packets");
    label.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gTransport,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.transport.bytes");
    label.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gTransport,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.transport.received");
    
    lblReceivedPackets = new Label(gTransport,SWT.NONE);
    lblReceivedPackets.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    lblReceivedBytes = new Label(gTransport,SWT.NONE);
    lblReceivedBytes.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gTransport,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.transport.sent");
    
    lblSentPackets = new Label(gTransport,SWT.NONE);
    lblSentPackets.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    lblSentBytes = new Label(gTransport,SWT.NONE);
    lblSentBytes.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
    
    label = new Label(gTransport,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.transport.in");
    data = new GridData();
    data.horizontalSpan = 3;
    label.setLayoutData(data);
    
    
    in = new Canvas(gTransport,SWT.NO_BACKGROUND);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 3;
    in.setLayoutData(data);
    inGraph = SpeedGraphic.getInstance();
    inGraph.initialize(in);
    
    label = new Label(gTransport,SWT.NONE);
    Messages.setLanguageText(label,"DHTView.transport.out");
    data = new GridData();
    data.horizontalSpan = 3;
    label.setLayoutData(data);
    
    out = new Canvas(gTransport,SWT.NO_BACKGROUND);
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 3;
    out.setLayoutData(data);
    outGraph = SpeedGraphic.getInstance();
    outGraph.initialize(out);
  
public voidinitialize(org.eclipse.swt.widgets.Composite composite)

    panel = new Composite(composite,SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    panel.setLayout(layout);
    
    yes_str = MessageText.getString( "Button.yes").replaceAll("&", "");
    no_str 	= MessageText.getString( "Button.no").replaceAll("&", "");
    
    initialiseGeneralGroup();
    initialiseDBGroup();
    
    initialiseTransportDetailsGroup();
    initialiseOperationDetailsGroup();
    
    initialiseActivityGroup();
  
public voidperiodicUpdate()

    if(dht == null) return;
    
    DHTTransportFullStats fullStats = dht.getTransport().getLocalContact().getStats();
    inGraph.addIntValue((int)fullStats.getAverageBytesReceived());
    outGraph.addIntValue((int)fullStats.getAverageBytesSent());
  
public voidrefresh()

    
    if(dht == null) { 
      init();
      return;
    }
    
    inGraph.refresh();
    outGraph.refresh();
    
    refreshGeneral();
    refreshDB();
    refreshTransportDetails();
    refreshOperationDetails();
    refreshActivity();
  
private voidrefreshActivity()

    if(activityChanged) {
      activityChanged = false;
      activities = dht.getControl().getActivities();
      activityTable.setItemCount(activities.length);
      activityTable.clearAll();
      //Dunno if still needed?
      activityTable.redraw();  
    }    
  
private voidrefreshDB()

  
         
    if(refreshIter == 0) {
	  DHTDBStats    dbStats = dht.getDataBase().getStats();
      lblKeys.setText("" + dbStats.getKeyCount());  
      int[] stats = dbStats.getValueDetails();
      lblValues.setText("" + stats[DHTDBStats.VD_VALUE_COUNT]);
      lblDirect.setText("" + stats[DHTDBStats.VD_DIRECT_SIZE]);
      lblIndirect.setText("" + stats[DHTDBStats.VD_INDIRECT_SIZE]);
      lblLocal.setText("" + stats[DHTDBStats.VD_LOCAL_SIZE]);
      lblDivFreq.setText("" + stats[DHTDBStats.VD_DIV_FREQ]);
      lblDivSize.setText("" + stats[DHTDBStats.VD_DIV_SIZE]);
    } else {
      refreshIter++;
      if(refreshIter == 100) refreshIter = 0;
    }

  
private voidrefreshGeneral()

    DHTControlStats controlStats = dht.getControl().getStats();
    DHTRouterStats routerStats = dht.getRouter().getStats();
    lblUpTime.setText(TimeFormatter.format(controlStats.getRouterUptime() / 1000));
    lblNumberOfUsers.setText("" + controlStats.getEstimatedDHTSize());
    lblReachable.setText(dht.getTransport().isReachable()?yes_str:no_str);
    
    DHTNATPuncher puncher = dht.getNATPuncher();
    
    String	puncher_str;
    
    if ( puncher == null ){
    	puncher_str = "";
    }else{
    	puncher_str = puncher.operational()?yes_str:no_str;
    }
    
    lblRendezvous.setText(dht.getTransport().isReachable()?"":puncher_str);
    long[] stats = routerStats.getStats();
    lblNodes.setText("" + stats[DHTRouterStats.ST_NODES]);
    lblLeaves.setText("" + stats[DHTRouterStats.ST_LEAVES]);
    lblContacts.setText("" + stats[DHTRouterStats.ST_CONTACTS]);
    lblReplacements.setText("" + stats[DHTRouterStats.ST_REPLACEMENTS]);
    lblLive.setText("" + stats[DHTRouterStats.ST_CONTACTS_LIVE]);
    lblUnknown.setText("" + stats[DHTRouterStats.ST_CONTACTS_UNKNOWN]);
    lblDying.setText("" + stats[DHTRouterStats.ST_CONTACTS_DEAD]);
  
private voidrefreshOperationDetails()

   
    DHTTransportStats   transportStats = dht.getTransport().getStats();
    long[] pings = transportStats.getPings();
    for(int i = 0 ; i < 4 ; i++) {
      lblPings[i].setText("" + pings[i]);
    }
    
    long[] findNodes = transportStats.getFindNodes();
    for(int i = 0 ; i < 4 ; i++) {
      lblFindNodes[i].setText("" + findNodes[i]);
    }
    
    long[] findValues = transportStats.getFindValues();
    for(int i = 0 ; i < 4 ; i++) {
      lblFindValues[i].setText("" + findValues[i]);
    }
    
    long[] stores = transportStats.getStores();
    for(int i = 0 ; i < 4 ; i++) {
      lblStores[i].setText("" + stores[i]);
    }
    long[] data = transportStats.getData();
    for(int i = 0 ; i < 4 ; i++) {
      lblData[i].setText("" + data[i]);
    }
  
private voidrefreshTransportDetails()

    DHTTransportStats   transportStats = dht.getTransport().getStats();
    lblReceivedBytes.setText(DisplayFormatters.formatByteCountToKiBEtc(transportStats.getBytesReceived()));
    lblSentBytes.setText(DisplayFormatters.formatByteCountToKiBEtc(transportStats.getBytesSent()));
    lblReceivedPackets.setText("" + transportStats.getPacketsReceived());
    lblSentPackets.setText("" + transportStats.getPacketsSent());