|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 4 of 5
The RemoteCopyTask, which is run on the local machine, creates a Command object. The Command object loads the file into a byte array to prepare for the transfer to the server. On execute, this command object is serialized
and passed to the remote machine.
The RemoteAntHandler object receives the Command object from the ObjectInputStream. The RemoteAntHandler then deserializes the object and determines what command to execute. At this point, I have simplified the example and included
both commands in the same handler as different branches of the if statement. Ideally, another framework would let the server process those commands more efficiently.
Because the received command is a copy command, the handler will write the file to disk with the filename and directory as specified in the Command object.
In addition to the remote copy command, I have included a remote ant command. In this case, the local machine can execute the ant command on the remote machine.
I use the RemoteAntTask, which again extends the RemoteTask object. The RemoteAntTask simply sets the command to Ant. Future expansions of this task include the addition of a buildfile specification and additional
functionality contained in the original ant command itself.
When the RemoteAntHandler object receives and then deserializes the Command object, it will determine that it should invoke the ant command. That is handled by having the server spawn another process calling ant. Why spawn another process? Due to the architecture of the Ant code, it's not currently possible to call ant and maintain the JVM. So I've spawned another process, using the RunProcess object. Please note that the script that invokes the RemoteServer specifies some command line arguments such as deployment directory. That was done to limit the potential harm that an errant
buildfile could cause on the remote machine.
The last step in extending Ant to perform the remote commands is to incorporate these commands in the buildfile. The following buildfile includes the new commands:
<project name="foo" default="ant" basedir=".">
<target name="init" >
<taskdef name="remoteCopy" classname="local.RemoteCopyTask"/>
<taskdef name="remoteAnt" classname="local.RemoteAntTask"/>
</target>
<target name="deploy" depends="init2">
<remoteCopy machine="machinename.groupserve.com" port="9090"
directory="e:\deve\ant\article\deploy" filetype="text"
filename="build.xml" />
<remoteCopy machine="machinename.groupserve.com" port="9090"
directory="e:\deve\ant\article\deploy" filetype="binary"
filename="app.jar" />
</target>
<target name="ant" depends="deploy">
<remoteAnt machine="machinename.groupserve.com" port="9090" />
</target>
</project>
Here's the first line of interest:
<taskdef name="remoteCopy" classname="local.RemoteCopyTask" />
This line creates a taskdef task that associates the name remoteCopy with the class contained in the file local.RemoteCopyTask. From this point forward, I can call the task remoteCopy, and my new code will be executed. For example: