Stream gobblers in RunShellImpl

<depstein-6g8wRflRTwWrN/MWgto1swC/[email protected]> Tue, 7 Dec 2010 13:22:39 +0300
Newsgroups gmane.comp.java.smartfrog.user
Message-ID <29F36C7C98AB09499B1A209D48EAA615B4FF7AD6BF@mail2a.alliedtesting.com>
--===============8905629088513824312==
Content-Language: en-US
Content-Type: multipart/alternative;
	boundary="_000_29F36C7C98AB09499B1A209D48EAA615B4FF7AD6BFmail2aalliedt_"

--_000_29F36C7C98AB09499B1A209D48EAA615B4FF7AD6BFmail2aalliedt_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi,

I have extended RunShellImpl to add some features. In particular, I overrod=
e didProcessFail method, which now scans process standard output and matche=
s it to a user-supplied pattern. I use the parent class's setOutputStreamOb=
j method to supply my OutputStreamIntf implementation, based on ByteArrayOu=
tputStream, to capture the process standard output.  (By the way, why isn't=
 there a similar way to capture standard error?)

One problem that I ran into is that sometimes when didProcessFail is called=
, the output stream gobbler has not finished writing to my output stream, a=
nd so when I inspect the stream contents, I don't get the full output. The =
reason, I think, is that the execute() method of the parent class launches =
the two stream gobblers and  sets them adrift, never joining to the parent =
thread, so that there is no control over their execution. I think it would =
be better if the stream gobblers were explicitly joined in the run() method=
, after the process returns.

Unfortunately, since nearly all methods of RunShellImpl are declared as pri=
vate, there is only so much I can do in my derived class. Do you have any s=
uggestions for me? For now, I just added a short wait before inspecting the=
 output stream, to give time to the stream gobbler to finish.

Thanks,
Dmitry

--_000_29F36C7C98AB09499B1A209D48EAA615B4FF7AD6BFmail2aalliedt_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40"><head><meta http-equiv=3DContent-Type content=
=3D"text/html; charset=3Dus-ascii"><meta name=3DGenerator content=3D"Micros=
oft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue vli=
nk=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal>Hi,<o:p></o:p></=
p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>I have ext=
ended RunShellImpl to add some features. In particular, I overrode didProce=
ssFail method, which now scans process standard output and matches it to a =
user-supplied pattern. I use the parent class&#8217;s setOutputStreamObj me=
thod to supply my OutputStreamIntf implementation, based on ByteArrayOutput=
Stream, to capture the process standard output. &nbsp;(By the way, why isn&=
#8217;t there a similar way to capture standard error?)<o:p></o:p></p><p cl=
ass=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>One problem that =
I ran into is that sometimes when didProcessFail is called, the output stre=
am gobbler has not finished writing to my output stream, and so when I insp=
ect the stream contents, I don&#8217;t get the full output. The reason, I t=
hink, is that the execute() method of the parent class launches the two str=
eam gobblers and &nbsp;sets them adrift, never joining to the parent thread=
, so that there is no control over their execution. I think it would be bet=
ter if the stream gobblers were explicitly joined in the run() method, afte=
r the process returns.<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p>=
</p><p class=3DMsoNormal>Unfortunately, since nearly all methods of RunShel=
lImpl are declared as private, there is only so much I can do in my derived=
 class. Do you have any suggestions for me? For now, I just added a short w=
ait before inspecting the output stream, to give time to the stream gobbler=
 to finish.<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p clas=
s=3DMsoNormal>Thanks,<o:p></o:p></p><p class=3DMsoNormal>Dmitry<o:p></o:p><=
/p></div></body></html>=

--_000_29F36C7C98AB09499B1A209D48EAA615B4FF7AD6BFmail2aalliedt_--


--===============8905629088513824312==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d
--===============8905629088513824312==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Smartfrog-users mailing list
Smartfrog-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/smartfrog-users

--===============8905629088513824312==--