Examples of WeakReference


Examples of cli.System.WeakReference

    public WeakIdentityMap()
    {
        for (int i = 0; i < keys.length; i++)
        {
            keys[i] = new WeakReference(null, true);
            // NOTE we suppress finalization, to make sure the WeakReference continues to work
            // while the AppDomain is finalizing for unload (note that for this to work,
            // the code that instantiates us also has to call SuppressFinalize on us.)
            GC.SuppressFinalize(keys[i]);
        }
View Full Code Here

Examples of com.sun.star.uno.WeakReference

        boolean[] r= new boolean[50];
        int i= 0;

        WeakBase aObj1= new WeakBase();
//        WeakBase aObj2= new WeakBase();
        WeakReference wr1= new WeakReference(aObj1);
        WeakReference wr2= new WeakReference(wr1);
       
        r[i++]= wr1.get() == aObj1;
        r[i++]= wr2.get() == aObj1;
        aObj1= null;
       
          //        Object obj= ref.get();
        System.out.println("Wait 5 sec");
        for(int c= 0; c < 50; c++)
        {
            try
            {
                Thread.currentThread().sleep(100);
                System.gc();
                System.runFinalization();
            }catch (InterruptedException ie)
            {
            }
        }
        r[i++]= wr1.get() == null;
        r[i++]= wr2.get() == null;
   
        boolean bOk= true;
        for (int c= 0; c < i; c++)
            bOk= bOk && r[c];
        if (bOk == false)
View Full Code Here

Examples of java.lang.ref.WeakReference

     *  Get a Script wrapper for any given object. If the object implements the IPathElement
     *  interface, the getPrototype method will be used to retrieve the name of the prototype
     * to use. Otherwise, a Java-Class-to-Script-Prototype mapping is consulted.
     */
    public Scriptable getElementWrapper(Object e) {
        WeakReference ref = (WeakReference) wrappercache.get(e);
        Wrapper wrapper = ref == null ? null : (Wrapper) ref.get();

        if (wrapper == null || wrapper.unwrap() != e) {
            // Gotta find out the prototype name to use for this object...
            String prototypeName = app.getPrototypeName(e);
            Scriptable op = getPrototype(prototypeName);

            if (op == null) {
                // no prototype found, return an unscripted wrapper
                wrapper = new NativeJavaObject(global, e, e.getClass());
            } else {
                wrapper = new JavaObject(global, e, prototypeName, op, this);
            }

            wrappercache.put(e, new WeakReference(wrapper));
        }

        return (Scriptable) wrapper;
    }
View Full Code Here

Examples of java.lang.ref.WeakReference

 
              FileSkeleton info = new FileSkeleton() {
 
                private CacheFile   read_cache_file;
                // do not access this field directly, use lazyGetFile() instead
                private WeakReference dataFile = new WeakReference(null);
 
                public void
                setPriority(int b)
                {
                  priority    = b;
 
                  DiskManagerImpl.storeFilePriorities( download_manager, res );
 
                  listener.filePriorityChanged( this );
                }
 
                public void
                setSkipped(boolean _skipped)
                {
                  if ( !_skipped && getStorageType() == ST_COMPACT ){
                    if ( !setStorageType( ST_LINEAR )){
                      return;
                    }
                  }
 
                  if ( !_skipped && getStorageType() == ST_REORDER_COMPACT ){
                    if ( !setStorageType( ST_REORDER )){
                      return;
                    }
                  }

                  skipped = _skipped;
 
                  DiskManagerImpl.storeFilePriorities( download_manager, res );
                 
                  if(!_skipped)
                  {
                    boolean[] toCheck = new boolean[fileSetSkeleton.nbFiles()];
                    toCheck[file_index] = true;
                    doFileExistenceChecks(fileSetSkeleton, toCheck, download_manager, true);                     
                  }
                 
 
                  listener.filePriorityChanged( this );
                }
 
                public int
                getAccessMode()
                {
                  return( READ );
                }
 
                public long
                getDownloaded()
                {
                  return( downloaded );
                }
 
                public void
                setDownloaded(
                  long    l )
                {
                  downloaded  = l;
                }
 
                public String
                getExtension()
                {
                  String    ext   = lazyGetFile().getName();
                 
                      if ( incomplete_suffix != null && ext.endsWith( incomplete_suffix )){
                       
                        ext = ext.substring( 0, ext.length() - incomplete_suffix.length());
                      }

                  int separator = ext.lastIndexOf(".");
                  if (separator == -1)
                    separator = 0;
                  return ext.substring(separator);
                }
 
                public int
                getFirstPieceNumber()
                {
                  return( torrent_file.getFirstPieceNumber());
                }
 
                public int
                getLastPieceNumber()
                {
                  return( torrent_file.getLastPieceNumber());
                }
 
                public long
                getLength()
                {
                  return( torrent_file.getLength());
                }
 
                public int
                getIndex()
                {
                  return( file_index );
                }
 
                public int
                getNbPieces()
                {
                  return( torrent_file.getNumberOfPieces());
                }
 
                public int
                getPriority()
                {
                  return( priority );
                }
 
                public boolean
                isSkipped()
                {
                  return( skipped );
                }
 
                public DiskManager
                getDiskManager()
                {
                  return( null );
                }
 
                public DownloadManager
                getDownloadManager()
                {
                  return( download_manager );
                }
 
                public File
                getFile(
                  boolean follow_link )
                {
                  if ( follow_link ){
 
                    File link = getLink();
 
                    if ( link != null ){
 
                      return( link );
                    }
                  }
                  return lazyGetFile();
                }
 
                private File lazyGetFile()
                {
                  File toReturn = (File)dataFile.get();
                  if(toReturn != null)
                    return toReturn;
 
                  TOTorrent tor = download_manager.getTorrent();
 
                  String  path_str = root_dir;
                  File simpleFile = null;
 
                  // for a simple torrent the target file can be changed
 
                  if ( tor.isSimpleTorrent()){
 
                    simpleFile = download_manager.getAbsoluteSaveLocation();
 
                  }else{
                    byte[][]path_comps = torrent_file.getPathComponents();
 
                    for (int j=0;j<path_comps.length;j++){
 
                      String comp;
                      try
                      {
                        comp = locale_decoder.decodeString( path_comps[j] );
                      } catch (UnsupportedEncodingException e)
                      {
                        Debug.printStackTrace(e);
                        comp = "undecodableFileName"+file_index;
                      }
 
                      comp = FileUtil.convertOSSpecificChars( comp,  j != path_comps.length-1 );
 
                      path_str += (j==0?"":File.separator) + comp;
                    }
                  }
 
                  dataFile = new WeakReference(toReturn = simpleFile != null ? simpleFile : new File( path_str ));
 
                  //System.out.println("new file:"+toReturn);
                  return toReturn;
                }
 
View Full Code Here

Examples of java.lang.ref.WeakReference

  add(
    Object    obj )
  {
    if ( DEBUG ){
   
      list.add( new Object[]{ obj.getClass(), new WeakReference( obj )});
     
    }else{
     
      list.add( obj );
    }
View Full Code Here

Examples of java.lang.ref.WeakReference

     
      while( it.hasNext()){
       
        Object[]  entry  = (Object[])it.next();
       
        WeakReference  wr = (WeakReference)entry[1];
       
        Object  target = wr.get();
       
        if ( target == null ){
         
          it.remove();
         
View Full Code Here

Examples of java.lang.ref.WeakReference

     
      while( it.hasNext()){
                 
        Object[]  entry  = (Object[])it.next();
       
        WeakReference  wr = (WeakReference)entry[1];
       
        Object  target = wr.get();
       
        if ( target == null ){
         
          it.remove();
         
View Full Code Here

Examples of java.lang.ref.WeakReference

       
        while( temp_it.hasNext()){
         
          Object[]  entry  = (Object[])temp_it.next();
         
          WeakReference  wr = (WeakReference)entry[1];
         
          Object  target = wr.get();

          if ( target == lr ){
           
            it = temp_it;
           
View Full Code Here

Examples of java.lang.ref.WeakReference

        timers_mon.enter();
        if (timers == null) {
          timers = new ArrayList();
          AEDiagnostics.addEvidenceGenerator(new evidenceGenerator());
        }
        timers.add(new WeakReference(this));
      } finally {
        timers_mon.exit();
      }
    }
View Full Code Here

Examples of java.lang.ref.WeakReference

    if (DEBUG_TIMERS) {
      try {
        timers_mon.enter();
        // crappy
        for (Iterator iter = timers.iterator(); iter.hasNext();) {
          WeakReference timerRef = (WeakReference) iter.next();
          Object timer = timerRef.get();
          if (timer == null || timer == this) {
            iter.remove();
          }
        }
      } finally {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.