[VFS] Funny result for HDFS FileObject.equals

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[VFS] Funny result for HDFS FileObject.equals

Roger Whitcomb
Hi,
                I'm using Commons VFS inside an Apache Pivot remote file browser and I'm getting a strange result when switching between different HDFS hosts.  I have two FileObjects, with different host:port (but the same directory name), and they compare equal (i.e., the FileObject.equals(...) method returns true, when they are clearly not the same.  Any thoughts?
                Here is the code and my results:
System.out.format("VFSBrowserSheet.setRootDirectory: does '%1$s' exist()? %2$s%n", rootDirectory, rootDirectory.exists());
        if (rootDirectory.exists()) {
            FileObject previousRootDirectory = this.rootDirectory;

System.out.format("VFSBrowserSheet.setRootDirectory: previousRootDirectory = %1$s%n", previousRootDirectory);
System.out.format("VFSBrowserSheet.setRootDirectory: rootDirectory[%1$s].equals(previousRootDirectory[%2$s])? %3$s%n", rootDirectory, previousRootDirectory, rootDirectory.equals(previousRootDirectory));
            if (!rootDirectory.equals(previousRootDirectory)) {
                this.rootDirectory = rootDirectory;
                selectedFiles.clear();
System.out.format("VFSBrowserSheet.setRootDirectory, calling 'rootDirectoryChanged'%n");
                fileBrowserSheetListeners.rootDirectoryChanged(this, previousRootDirectory);
            }

VFSBrowserSheet.setRootDirectory: does 'hdfs://chhadoop-master:9000/' exist()? true
VFSBrowserSheet.setRootDirectory: previousRootDirectory = hdfs://chcluster2-master:8020/
VFSBrowserSheet.setRootDirectory: rootDirectory[hdfs://chhadoop-master:9000/].equals(previousRootDirectory[hdfs://chcluster2-master:8020/])? True

Thanks,
~Roger Whitcomb


Reply | Threaded
Open this post in threaded view
|

RE: [VFS] Funny result for HDFS FileObject.equals

Roger Whitcomb
So, the reason is that HdfsFileObject.equals only compares the paths, and not the HdfsFileSystem object it is attached to.

    @Override
    public boolean equals(final Object o)
    {
        if (null == o)
        {
            return false;
        }
        if (o == this)
        {
            return true;
        }
        if (o instanceof HdfsFileObject)
        {
            final HdfsFileObject other = (HdfsFileObject) o;
            if (other.path.equals(this.path))
            {
                return true;
            }
        }
        return false;
    }

And likewise, "hashCode" only returns the hash of the path.

Think I will file a JIRA with a patch for this.

Thanks,
~Roger Whitcomb

-----Original Message-----
From: Roger Whitcomb [mailto:[hidden email]]
Sent: Monday, May 05, 2014 3:41 PM
To: Commons Users List
Subject: [VFS] Funny result for HDFS FileObject.equals

Hi,
                I'm using Commons VFS inside an Apache Pivot remote file browser and I'm getting a strange result when switching between different HDFS hosts.  I have two FileObjects, with different host:port (but the same directory name), and they compare equal (i.e., the FileObject.equals(...) method returns true, when they are clearly not the same.  Any thoughts?
                Here is the code and my results:
System.out.format("VFSBrowserSheet.setRootDirectory: does '%1$s' exist()? %2$s%n", rootDirectory, rootDirectory.exists());
        if (rootDirectory.exists()) {
            FileObject previousRootDirectory = this.rootDirectory;

System.out.format("VFSBrowserSheet.setRootDirectory: previousRootDirectory = %1$s%n", previousRootDirectory);
System.out.format("VFSBrowserSheet.setRootDirectory: rootDirectory[%1$s].equals(previousRootDirectory[%2$s])? %3$s%n", rootDirectory, previousRootDirectory, rootDirectory.equals(previousRootDirectory));
            if (!rootDirectory.equals(previousRootDirectory)) {
                this.rootDirectory = rootDirectory;
                selectedFiles.clear();
System.out.format("VFSBrowserSheet.setRootDirectory, calling 'rootDirectoryChanged'%n");
                fileBrowserSheetListeners.rootDirectoryChanged(this, previousRootDirectory);
            }

VFSBrowserSheet.setRootDirectory: does 'hdfs://chhadoop-master:9000/' exist()? true
VFSBrowserSheet.setRootDirectory: previousRootDirectory = hdfs://chcluster2-master:8020/
VFSBrowserSheet.setRootDirectory: rootDirectory[hdfs://chhadoop-master:9000/].equals(previousRootDirectory[hdfs://chcluster2-master:8020/])? True

Thanks,
~Roger Whitcomb




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [VFS] Funny result for HDFS FileObject.equals

garydgregory
On Mon, May 5, 2014 at 7:09 PM, Roger Whitcomb <[hidden email]>wrote:

> So, the reason is that HdfsFileObject.equals only compares the paths, and
> not the HdfsFileSystem object it is attached to.
>
>     @Override
>     public boolean equals(final Object o)
>     {
>         if (null == o)
>         {
>             return false;
>         }
>         if (o == this)
>         {
>             return true;
>         }
>         if (o instanceof HdfsFileObject)
>         {
>             final HdfsFileObject other = (HdfsFileObject) o;
>             if (other.path.equals(this.path))
>             {
>                 return true;
>             }
>         }
>         return false;
>     }
>
> And likewise, "hashCode" only returns the hash of the path.
>
> Think I will file a JIRA with a patch for this.
>

Great news as we are gearing up for a 2.1 release.

Gary


>
> Thanks,
> ~Roger Whitcomb
>
> -----Original Message-----
> From: Roger Whitcomb [mailto:[hidden email]]
> Sent: Monday, May 05, 2014 3:41 PM
> To: Commons Users List
> Subject: [VFS] Funny result for HDFS FileObject.equals
>
> Hi,
>                 I'm using Commons VFS inside an Apache Pivot remote file
> browser and I'm getting a strange result when switching between different
> HDFS hosts.  I have two FileObjects, with different host:port (but the same
> directory name), and they compare equal (i.e., the FileObject.equals(...)
> method returns true, when they are clearly not the same.  Any thoughts?
>                 Here is the code and my results:
> System.out.format("VFSBrowserSheet.setRootDirectory: does '%1$s' exist()?
> %2$s%n", rootDirectory, rootDirectory.exists());
>         if (rootDirectory.exists()) {
>             FileObject previousRootDirectory = this.rootDirectory;
>
> System.out.format("VFSBrowserSheet.setRootDirectory: previousRootDirectory
> = %1$s%n", previousRootDirectory);
> System.out.format("VFSBrowserSheet.setRootDirectory:
> rootDirectory[%1$s].equals(previousRootDirectory[%2$s])? %3$s%n",
> rootDirectory, previousRootDirectory,
> rootDirectory.equals(previousRootDirectory));
>             if (!rootDirectory.equals(previousRootDirectory)) {
>                 this.rootDirectory = rootDirectory;
>                 selectedFiles.clear();
> System.out.format("VFSBrowserSheet.setRootDirectory, calling
> 'rootDirectoryChanged'%n");
>                 fileBrowserSheetListeners.rootDirectoryChanged(this,
> previousRootDirectory);
>             }
>
> VFSBrowserSheet.setRootDirectory: does 'hdfs://chhadoop-master:9000/'
> exist()? true
> VFSBrowserSheet.setRootDirectory: previousRootDirectory =
> hdfs://chcluster2-master:8020/
> VFSBrowserSheet.setRootDirectory:
> rootDirectory[hdfs://chhadoop-master:9000/].equals(previousRootDirectory[hdfs://chcluster2-master:8020/])?
> True
>
> Thanks,
> ~Roger Whitcomb
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Reply | Threaded
Open this post in threaded view
|

RE: [VFS] Funny result for HDFS FileObject.equals

Roger Whitcomb
Hi Gary,
   The JIRA issue is https://issues.apache.org/jira/browse/VFS-523 and the patch file is attached to the issue. I have tested the patch in our application and it seems to be working fine.

Appreciate you (or someone) having a look.

Thanks,
~Roger
________________________________________
From: Gary Gregory <[hidden email]>
Sent: Tuesday, May 06, 2014 6:39:07 AM
To: Commons Users List
Subject: Re: [VFS] Funny result for HDFS FileObject.equals

On Mon, May 5, 2014 at 7:09 PM, Roger Whitcomb <[hidden email]>wrote:

> So, the reason is that HdfsFileObject.equals only compares the paths, and
> not the HdfsFileSystem object it is attached to.
>
>     @Override
>     public boolean equals(final Object o)
>     {
>         if (null == o)
>         {
>             return false;
>         }
>         if (o == this)
>         {
>             return true;
>         }
>         if (o instanceof HdfsFileObject)
>         {
>             final HdfsFileObject other = (HdfsFileObject) o;
>             if (other.path.equals(this.path))
>             {
>                 return true;
>             }
>         }
>         return false;
>     }
>
> And likewise, "hashCode" only returns the hash of the path.
>
> Think I will file a JIRA with a patch for this.
>

Great news as we are gearing up for a 2.1 release.

Gary


>
> Thanks,
> ~Roger Whitcomb
>
> -----Original Message-----
> From: Roger Whitcomb [mailto:[hidden email]]
> Sent: Monday, May 05, 2014 3:41 PM
> To: Commons Users List
> Subject: [VFS] Funny result for HDFS FileObject.equals
>
> Hi,
>                 I'm using Commons VFS inside an Apache Pivot remote file
> browser and I'm getting a strange result when switching between different
> HDFS hosts.  I have two FileObjects, with different host:port (but the same
> directory name), and they compare equal (i.e., the FileObject.equals(...)
> method returns true, when they are clearly not the same.  Any thoughts?
>                 Here is the code and my results:
> System.out.format("VFSBrowserSheet.setRootDirectory: does '%1$s' exist()?
> %2$s%n", rootDirectory, rootDirectory.exists());
>         if (rootDirectory.exists()) {
>             FileObject previousRootDirectory = this.rootDirectory;
>
> System.out.format("VFSBrowserSheet.setRootDirectory: previousRootDirectory
> = %1$s%n", previousRootDirectory);
> System.out.format("VFSBrowserSheet.setRootDirectory:
> rootDirectory[%1$s].equals(previousRootDirectory[%2$s])? %3$s%n",
> rootDirectory, previousRootDirectory,
> rootDirectory.equals(previousRootDirectory));
>             if (!rootDirectory.equals(previousRootDirectory)) {
>                 this.rootDirectory = rootDirectory;
>                 selectedFiles.clear();
> System.out.format("VFSBrowserSheet.setRootDirectory, calling
> 'rootDirectoryChanged'%n");
>                 fileBrowserSheetListeners.rootDirectoryChanged(this,
> previousRootDirectory);
>             }
>
> VFSBrowserSheet.setRootDirectory: does 'hdfs://chhadoop-master:9000/'
> exist()? true
> VFSBrowserSheet.setRootDirectory: previousRootDirectory =
> hdfs://chcluster2-master:8020/
> VFSBrowserSheet.setRootDirectory:
> rootDirectory[hdfs://chhadoop-master:9000/].equals(previousRootDirectory[hdfs://chcluster2-master:8020/])?
> True
>
> Thanks,
> ~Roger Whitcomb
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]