yoshi | 0451f28 | 2013-11-22 15:48:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * To change this template, choose Tools | Templates |
| 3 | * and open the template in the editor. |
| 4 | */ |
| 5 | package net.onrc.onos.graph; |
| 6 | |
| 7 | import com.tinkerpop.blueprints.impls.ramcloud.RamCloudGraph; |
| 8 | import com.tinkerpop.frames.FramedGraph; |
| 9 | import java.io.File; |
| 10 | import org.apache.commons.configuration.Configuration; |
| 11 | import org.apache.commons.configuration.ConfigurationException; |
| 12 | import org.apache.commons.configuration.PropertiesConfiguration; |
| 13 | |
| 14 | /** |
| 15 | * |
| 16 | * @author nickkaranatsios |
| 17 | */ |
| 18 | public class RamCloudDBConnection extends DBConnection { |
| 19 | private RamCloudGraph graph; |
| 20 | |
| 21 | public RamCloudDBConnection(final String dbConfigFile) { |
| 22 | System.out.println("dbconfigfile is + "+ dbConfigFile); |
| 23 | final String coordinatorURL = open(getConfiguration(new File(dbConfigFile))); |
| 24 | graph = new RamCloudGraph(coordinatorURL); |
| 25 | } |
| 26 | |
| 27 | @Override |
| 28 | public FramedGraph getFramedGraph() { |
| 29 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public void addEventListener(LocalGraphChangedListener listener) { |
| 34 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public Boolean isValid() { |
| 39 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public void commit() { |
| 44 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void rollback() { |
| 49 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public void close() { |
| 54 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
| 55 | } |
| 56 | |
| 57 | private static final Configuration getConfiguration(final File dirOrFile) { |
| 58 | if (dirOrFile == null) { |
| 59 | throw new IllegalArgumentException("Need to specify a configuration file or storage directory"); |
| 60 | } |
| 61 | |
| 62 | if (!dirOrFile.isFile()) { |
| 63 | throw new IllegalArgumentException("Location of configuration must be a file"); |
| 64 | } |
| 65 | |
| 66 | try { |
| 67 | return new PropertiesConfiguration(dirOrFile); |
| 68 | } catch (ConfigurationException e) { |
| 69 | throw new IllegalArgumentException("Could not load configuration at: " + dirOrFile, e); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | private String open(final Configuration configuration) { |
| 74 | final String coordinatorURL = configuration.getString("ramcloud.coordinator", null); |
| 75 | if (coordinatorURL == null) { |
| 76 | throw new RuntimeException("Configuration must contain a valid 'coordinatorURL' setting"); |
| 77 | } |
| 78 | return coordinatorURL; |
| 79 | } |
| 80 | } |