Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Monitor progress of UploadPack

On Wed, Jun 2, 2010 at 1:12 PM, Sebastian Himberger
<sebastian.himberger@xxxxxx> wrote:
>
> I'm using the UploadPack class with custom IO streams in a Server
> application. I basically simulate a simple SSH shell using Apache Mina.

So you are using the MINA SSHD code to provide an SSH server, with
JGit's UploadPack class hosted inside of that?  That is a
configuration I'm rather familiar with, as its what I use in Gerrit
Code Review... and how I found myself contributing occasional changes
to MINA SSHD.  :-)

> I run all commands in a seperate Thread and want my thread to wait for
> UploadPack#upload() to complete. Before continuing execution. Is there
> some kind of monitor available? My code looks something like that:

No.  You'll need to monitor the thread you are starting to determine
when its done.  You can do this by having it use a Semaphore or
CountDownLatch, or just setup a typical "boolean done" flag inside of
an object and use that object's native monitor to wait for and signal
when the flag is changed by the thread just before it terminates.

>    @Override
>    public void service() throws Exception {
>        Thread uploadThread = new Thread(new Runnable() {
>            @Override
>            public void run() {
>                try {
>                    UploadPack up = new UploadPack(new Repository(new
> File("C:/tem/jgit/.git")));
>                    up.upload(getInputStream(), getOutputStream(),
> getErrorStream());
>                } catch (IOException ioe) {
>                    throw new RuntimeException("UploadPack produced an
> IO Exception",ioe);
>                }
>            }
>        });
>        uploadThread.start();
>    }
>
> But it seems that UploadPack kicks of some background IO and I need to
> wait for that to finish.

It doesn't do background IO.  The upload() method is blocking and runs
until completion.  Its expecting to perform IO with the client by
writing to the OutputStream and reading from the InputStream until the
fetch transaction is complete.

Within MINA SSHD these streams only exchange data when the IoProcessor
thread from the MINA thread pool is able to execute the data
transfers.   Your application's CommandFactory and Command.start() is
called on the IoProcessor thread.  No data can be exchanged until
after Command.start() has returned all the way back to the caller and
the IoProcessor thread is able to go back into the main MINA event
loop.

You didn't give me much context to go on here with the snippet of your
service() method, but I suspect you are somehow tying up the
IoProcessor thread and not returning back to the MINA event loop, so
no data traffic occurs with the client.  I can however tell you that
stock JGit works great inside of MINA SSHD... its what we use to
develop JGit itself in with our Gerrit Code Review server at
egit.eclipse.org.  :-)

I hope that helps.

--
Shawn.


Back to the top