directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r786316 - /directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/IndexValueSerializer.java
Date Thu, 18 Jun 2009 22:21:57 GMT
Author: elecharny
Date: Thu Jun 18 22:21:57 2009
New Revision: 786316

URL: http://svn.apache.org/viewvc?rev=786316&view=rev
Log:
Added a first preliminary class to serialize  index in JDBM. it's pretty much a skeleton roght
now

Added:
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/IndexValueSerializer.java

Added: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/IndexValueSerializer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/IndexValueSerializer.java?rev=786316&view=auto
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/IndexValueSerializer.java
(added)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/IndexValueSerializer.java
Thu Jun 18 22:21:57 2009
@@ -0,0 +1,161 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.server.core.avltree.AvlTree;
+import org.apache.directory.server.core.avltree.AvlTreeMarshaller;
+import org.apache.directory.server.core.entry.ServerEntrySerializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import jdbm.btree.BTree;
+import jdbm.helper.Serializer;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class IndexValueSerializer implements Serializer
+{
+    private static final long serialVersionUID = 1L;
+    
+    /** the flag for a Long value*/
+    private static byte LONG_VALUE = 0;
+
+    /** the flag for a AvlTree value*/
+    private static byte AVL_TREE_VALUE = 0;
+
+    /** the flag for a BTree value*/
+    private static byte BTREE_VALUE = 0;
+
+    /** the logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( IndexValueSerializer.class
);
+
+    public Object deserialize( byte[] serialized ) throws IOException
+    {
+        return null;
+    }
+
+    /**
+     * Serialize the object. It can be a long, a BTree or an AvlTree
+     * 
+     * @param obj The object to serialize
+     * @return a byte[] containing the serialized value
+     * @throws IOException If the serialization failed
+     */
+    public byte[] serialize( Object obj ) throws IOException
+    {
+        if ( obj instanceof AvlTree )
+        {
+            LOG.debug( "Serializing an AvlTree" );
+            return serialize( (AvlTree<?>)obj );
+        }
+        else if ( obj instanceof BTree )
+        {
+            LOG.debug( "Serializing a BTree" );
+            return serialize( (BTree)obj );
+        }
+        else
+        {
+            LOG.debug( "Serializing a long [{}]", obj );
+            return serialize( (Long)obj );
+        }
+    }
+
+    
+    /**
+     * Serialize a Long value
+     */
+    private byte[] serialize( Long value ) throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        // First, write the type
+        out.write( LONG_VALUE );
+        
+        // Now, flush the Long 
+        out.writeLong( value );
+        
+        // And return the result
+        out.flush();
+
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( ">------------------------------------------------" );
+            LOG.debug( "Serializes a LONG value" );
+        }
+
+        return baos.toByteArray();
+    }
+
+    
+    /**
+     * Serialize an AvlTree value
+     */
+    private byte[] serialize( BTree bTree ) throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        // First, write the type
+        out.write( AVL_TREE_VALUE );
+        
+        // Marshal the AvlTree here. 
+        // TODO : add the code
+
+        out.flush();
+        
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( ">------------------------------------------------" );
+            LOG.debug( "Serializes an AVL tree" );
+        }
+
+        return baos.toByteArray();
+    }
+
+    
+    /**
+     * Serialize a BTree value
+     */
+    private byte[] serialize( AvlTree<?> avlTree ) throws IOException
+    {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        // First, write the type
+        out.write( BTREE_VALUE );
+        
+        out.flush();
+
+        if ( LOG.isDebugEnabled() )
+        {
+            LOG.debug( ">------------------------------------------------" );
+            LOG.debug( "Serializes an AVL tree" );
+        }
+
+        return baos.toByteArray();
+    }
+}



Mime
View raw message