/[xulu]/trunk.bakup/src/appl/parallel/data/xulugridfile/XuluGridSharedFileSystemLoader.java
ViewVC logotype

Annotation of /trunk.bakup/src/appl/parallel/data/xulugridfile/XuluGridSharedFileSystemLoader.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 77 - (hide annotations)
Wed Feb 10 16:14:27 2010 UTC (14 years, 10 months ago) by alfonx
File size: 4595 byte(s)
backup of trunk
1 mojays 2 package appl.parallel.data.xulugridfile;
2    
3     import java.awt.Rectangle;
4     import java.io.File;
5     import java.rmi.RemoteException;
6    
7     import appl.data.LoadingException;
8     import appl.parallel.client.ClientDataServer;
9     import appl.parallel.data.AbstractDataHandler;
10     import appl.parallel.data.PartitionDataHandler;
11     import appl.parallel.spmd.split.DataPartition;
12    
13     /**
14     * This is a loader for use with shared file systems like ocfs2 or gfs. It only
15     * works in conjunction with the {@link XuluWritableGridFile} and supports
16     * loading data from and into this file format. That means reading and writing
17     * is done directly into the file. The Xulu GUI won't notice changes if you do not
18     * reload the XuluWritableGrid!
19     *
20     * @see XuluGridFile
21     * @see XuluWritableGridFile
22     * @see PartitionDataHandler
23     *
24     * @author Dominik Appl
25     */
26     public class XuluGridSharedFileSystemLoader extends AbstractDataHandler{
27    
28     private String gridFileName;
29     private transient XuluWritableGridFile xuluWritableGridFile;
30    
31     /**
32     * constructs a new {@link XuluGridSharedFileSystemLoader}.
33     *
34     * @param rootID
35     * the id of the data
36     * @param client
37     * a spmd client which may be used to get metainformation on
38     * client side before transfering the loader to its destination
39     * @param partitionBounds
40     * the bounds of the partition to be retrieved on server side
41     * @param unloadBounds
42     * the bounds of the partition which is to be uploaded to the
43     * client after calculation (may only be the calculation area)
44     */
45     public XuluGridSharedFileSystemLoader(int rootID, ClientDataServer client, Rectangle partitionBounds, Rectangle unloadBounds) {
46     super(rootID, client, partitionBounds, unloadBounds);
47     DataPartition partition;
48     try {
49     partition = client.getData(rootID);
50     if (partition instanceof XuluWritableGridFile) {
51     XuluWritableGridFile xwg = (XuluWritableGridFile) partition;
52     gridFileName = xwg.getGridFileName();
53     }
54     else throw new UnsupportedOperationException("This Dataloader can only be used XuluGridFiles");
55     } catch (RemoteException e) {
56     // TODO Auto-generated catch block
57     e.printStackTrace();
58     }
59     }
60    
61    
62     /**
63     * only used by {@link #clone()}
64     */
65     private XuluGridSharedFileSystemLoader(int rootID, ClientDataServer spmdClient, Rectangle partitionBounds, Rectangle unloadBounds, String gridFileName) {
66     super(rootID, null, partitionBounds, unloadBounds);
67     this.gridFileName=gridFileName;
68     }
69    
70     /**
71     * Used for deserialization. Do not use for other purposes
72     */
73     public XuluGridSharedFileSystemLoader() {
74     super();
75     }
76    
77     /* (non-Javadoc)
78     * @see appl.data.AbstractDataHandler#newInstance(int, appl.parallel.client.SPMDClient, java.awt.Rectangle, java.awt.Rectangle)
79     */
80     public PartitionDataHandler newInstance(int rootID, ClientDataServer client, Rectangle partitionBounds, Rectangle unloadBounds) {
81     // TODO Auto-generated method stub
82     return new XuluGridSharedFileSystemLoader(rootID, client, partitionBounds, unloadBounds);
83     }
84    
85     /* (non-Javadoc)
86     * @see appl.data.AbstractDataHandler#getLoadInfo()
87     */
88     @Override
89     public String getLoadInfo() {
90     return "Trying to load " + gridFileName;
91     }
92    
93     /* (non-Javadoc)
94     * @see appl.data.AbstractDataHandler#getUnloadInfo()
95     */
96     @Override
97     public String getUnloadInfo() {
98     return "Trying to unload " + gridFileName;
99     }
100    
101     /** loads the data directly from the gridfile
102     * @see appl.parallel.data.AbstractDataHandler#load()
103     */
104     @Override
105     public DataPartition load() throws LoadingException {
106     //load from the gridfile
107     if(xuluWritableGridFile==null)
108     xuluWritableGridFile = new XuluWritableGridFile(new File(gridFileName));
109     data = xuluWritableGridFile.getPartition(partitionBounds);
110     return data;
111     }
112    
113     /** unloads into the file! not into the Xulu-Client or anything!
114     */
115     @Override
116     public void unload() {
117     //unload to the local file
118     if(xuluWritableGridFile==null)
119     xuluWritableGridFile = new XuluWritableGridFile(new File(gridFileName));
120     // construct return grid only if necessary
121     DataPartition returnPartition = null;
122     if (unloadBounds.equals(data.getPartitionBounds()))
123     returnPartition = data;
124     else
125     returnPartition = data.getPartition(unloadBounds);
126     xuluWritableGridFile.setPartition(returnPartition, unloadBounds);
127     }
128    
129     public PartitionDataHandler clone() {
130     return new XuluGridSharedFileSystemLoader(rootID, spmdClient, this.partitionBounds,
131     this.unloadBounds, this.gridFileName);
132     }
133     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26