Re: Swing unit testing

2010-01-12 Thread Roger Gilliar

Hi,

we use Jemmy for this purpose (https://jemmy.dev.java.net/)

Regards
  Roger


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: making sense of condp :

2010-01-03 Thread Roger Gilliar
Hi 

thanks for the answer, but I still have a problem understanding why (or when) I 
want to use ::. The thing I don't understand is, that  the function after : 
is an unary function with the result of the matching as an argument.  But the 
result of the match will alway be true, otherwise there would be no match.  Or 
have I misunderstood the API description ?

Regards
  Roger



why 

Am 02.01.2010 um 22:47 schrieb Meikel Brandmeyer:

 Hi,
 
 Am 02.01.2010 um 15:23 schrieb Roger Gilliar:
 
 I'm just trying to understand why I would use : in a condp expression. The 
 followjg code shows how I tried to write a test for condp, but the question 
 remains. Why would I want to use : ?
 
 See here: http://groups.google.com/group/clojure/msg/d9ef152e19f5416b
 
 It always interesting when the return value of the testing function is of 
 interest. Eg. with some…
 
 (condp some foo
  #{a b} : do-stuff-with-a-or-b
  #{x y} : same-with-x-or-y
  do-default)
 
 So here it is interesting what was actually the match…
 
 Sincerely
 Meikel
 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: whats the meaning of alias ?

2010-01-03 Thread Roger Gilliar

 As I understand it, the Clojure reader expects to be able to resolve
 namespace references as soon as it sees them. Since alias is a
 function, the c alias doesn't exist until sometime after the reader
 has already run.  I think you will encounter a similar problem with
 the import macro.

Ok,

that makes sense somehow. Thanks for the explanation.

Regards
  Roger

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: whats the meaning of alias ?

2010-01-03 Thread Roger Gilliar
Hi !

Now that you understand it, can you explain it me? :)
-
I said it makes sense  not that I understand it ;-)

The make sense part is:

Calling alias inside a do is something I probably won't do in production code. 
It would make more sense to call it after an import  (at least for me) wich 
resolves the problem.  

Maybe the reader does _not_ eagerly resolve c/foo when the top-level
enclosing form is a do, but it _does_ eagerly resolve c/foo when
the top-level enclosing form is a function?
---
Thats the part I don't understand yet.  Maybe bug or feature or something 
missing in the docs ?

BTW: I started to collect my findings on github: 
http://github.com/rogergl/clojure-api-by-example/

Regards
  Roger

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


making sense of condp :

2010-01-02 Thread Roger Gilliar
Hi,

I'm just trying to understand why I would use : in a condp expression. The 
followjg code shows how I tried to write a test for condp, but the question 
remains. Why would I want to use : ?

Regards
  Roger


(defn foo [x] 
(println x)
(condp = x
true 1
false 2
)
)


(testing ternary clause
(is (= 1
(condp = 25
1  : foo
25 : foo
42
)
))
)

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


whats the meaning of alias ?

2010-01-02 Thread Roger Gilliar
Hi !

Given the code below, I'm wondering why I get

No such namespace: c

It would be nice if some could explain to me what I'm doing wrong.


Regards
  Roger

(ns coretest
(:use [clojure.test])
)

(defn foo [x] 
(condp = x
true 1
false 2
)
)

(testing test alias function
(is (= 1 
(do
(alias 'c 'coretest)
(c/foo true)


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: logging.clj and org.apache.commons.logging

2009-10-06 Thread Roger Gilliar

Hi,

the import syntax for the java libs in the correspondig clojure  
contrib source is wrong. Just change them to the correct syntax and it  
works.
At least that worked for me.

Regards
   Roger


Am 06.10.2009 um 11:14 schrieb dan.pomoh...@gmail.com:


 Hi,

 I have a maven project with java and clojure files. When I try to use
 logging in clojure files the build fails with:

 [INFO] [clojure:compile {execution: default-cli}]
 Compiling ro.dpom.markers to /home/dan/project/target/classes
 Exception in thread main java.lang.ClassNotFoundException:  
 org.apache.commons.logging (logging.clj:97)

 But in pom.xml I have:

dependency
  groupIdcommons-logging/groupId
  artifactIdcommons-logging/artifactId
  version1.1.1/version
/dependency
dependency
groupIdlog4j/groupId
artifactIdlog4j/artifactId
version1.2.14/version
/dependency

 And the java classes from the same project using:

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;

 compile without problems.

 I use tapestry-snapshot for clojure-contrib version 1.0-SNAPSHOT and  
 clojure-maven-plugin.

 Thank you,
 Dan Pomohaci

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: server-socket on exit event

2009-10-01 Thread Roger Gilliar


 I want to write a simple socket server in Clojure. I want to perform
 some action when a client disconnects.
---
The following code works for me. read-input returns nil if the socket  
is closed (the client disconnects)

Regards
   Roger

(defn read-input []
(loop [result [] input (read-line)]
(if input
(if (= (first input) \#)
 result
(recur (conj result input) (read-line))
)
nil)))

(defn handle-client [in out]
(binding [
*in* (reader in)
]
(with-connection db
(let [outstream (writer out)]
(loop []
(let [xml (read-input)]
(if xml
(do
(send-answers 
(parse outstream (makestr xml)))
(recur))
(info 
disconnected

(def server (create-server *port* handle-client))

Am 01.10.2009 um 20:39 schrieb ngocdaothanh:



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: server-socket on exit event

2009-10-01 Thread Roger Gilliar


Am 01.10.2009 um 21:28 schrieb ngocdaothanh:

 Roger, your code is not event based.
What do you mean by not event based ?


Regards
   Roger

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: question regarding agents

2009-09-24 Thread Roger Gilliar
Thanks for the answer.

 Wrapping a mutable thing like an output stream in an agent seems  
 dubious to me.

It was intended to use an agent here since I need to control the  
access to the write object. But what I forgot was

' the validator succeeds or if no validator was given, the return  
value of the given fn will become the new state of the Agent.'

The function that was called by the agent returned nil, so the writer  
object was lost.

But as you said it is better to pass the out object  instead of the  
agent anyway.

Regards
   Roger



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Q: is there a better way to do this

2009-09-23 Thread Roger Gilliar

 And even then, ensure is often not needed and overkill. Make sure you
 have a real business requirement that the predicate remain true (or
 value fixed) on transaction completion. We need to move to a world in
--
It seems that my problem falls exactly in this category. Ensuring  
*consuming* prohibits that the consumer misses messages added to  
*data* . At least I hope that it does.

(def *data* (ref ()))
(def *consuming* (ref false))
(def *is-syncing* (ref true))
(def *consumer-agent* (agent '()))

(defn data-producer [value]
(if @*is-syncing*
(if (dosync
(if (ensure *consuming*)
  true
(do
(alter *data* conj value)
false)))
(do
(loop []
(Thread/sleep 100)
(if @*is-syncing*
(recur)))   


(defn producer []
(doseq [i (range 1)]
(data-producer i)))

(defn consume [agent]
(Thread/sleep 150)
(dosync
(ref-set *consuming* true))
(println Consuming started,  (count @*data*)  items to consume.)
(Thread/sleep 250)
(dosync
(ref-set *consuming* false)
(ref-set *is-syncing* false)))

(defn consumer []
(send-off *consumer-agent* consume))

(doseq [i (range 300)]
(future-call producer))

(consumer)

(shutdown-agents)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



question regarding agents

2009-09-23 Thread Roger Gilliar

I have the following code:

(defn handle-client [in out]
(binding [
*in* (reader in)
]
(with-connection db
(let [outstream (agent (writer out))]
(loop []
(let [xml (read-input)]
(if xml
(do
(send-answers 
(parse outstream (makestr xml)))
(recur))
(info 
disconnected


The problem is, that it doesn't work to assign an agent to the  
outstream. If I do, the content of the agent (the outstream in this  
case) is set to nil after it is passed to send-answers and all send- 
answers does is to store the agent in a struct.  Why that ? I

Regards
   Roger

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Architecting a large multi-threaded process

2009-09-23 Thread Roger Gilliar
 What I want is some way to schedule tasks to be executed by some set  
 of worker threads, and then be able to control the number of worker  
 threads on a server.  What I'm interested in is other people's  
 opinions on how I should architect this app.

This is exactly what we (a colleague and me) did with a large  C++ app  
and it works perfectly

One of the advantages I see in clojure  is the built-in support for  
concurrency. If I would feel that this support would not be suitable  
for the given task I would definitely choose Java with the  
java.util.concurrent package.

Regards
   Roger



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Q: is there a better way to do this

2009-09-22 Thread Roger Gilliar

Hi,

thanks a lot. Your code looks much better than mine. But there is one  
part that I don't understand:

(defn producer []
  (if (dosync (if (not @consuming)
(alter data conj 1)))
(recur)))


How can I be sure that no more data is added to data after @consuming  
was set to true ?

Regards
   Roger




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Q: is there a better way to do this

2009-09-22 Thread Roger Gilliar

 thanks a lot. Your code looks much better than mine. But there is one
 part that I don't understand:

 (defn producer []
  (if (dosync (if (not @consuming)
(alter data conj 1)))
(recur)))


After rereading the docs several times It seems that I begin to  
understand how this works. The values of the vars inside a dosync  
block are determined when the dosync block starts. This makes it  
impossible that @consuming changes after the dosync block is entered.

True ?

The remaining question is: Is it possible that data is added to data  
after the consumer is started ?

Regards
   Roger


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Q: is there a better way to do this

2009-09-22 Thread Roger Gilliar

 .. It waits until the value is actually needed. For
 more details on this, see http://ociweb.com/mark/stm/article.html.
.
Great article.Thanks !

Roger


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Q: how to solve this concurrency problem ?

2009-09-21 Thread Roger Gilliar


Am 21.09.2009 um 06:50 schrieb Roger Gilliar:


 2.)  I modify the code like this:

 (if cache
   (cache-message content)
   (if (mesage-cache-agent-is-running)
   (send-of *message-cache-agent* send-last-message-with 
 content
 )

---
This will not work, since it could happend that  cached message are  
sent after the normal message process is started.

Regards
   Roger

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Q: dosync semantics

2009-09-21 Thread Roger Gilliar

I still have some problems to correctly understand the dosync  
semantic.  What happens exaclty if two threads try to modify the same  
list:

Example

thread 1:

(dosync
append an item to a list
...
)

thread 2:

(dosync
remove an item from a list
..
)

Is it true that If thread 1 is executed 'before' thread 2 all changes  
in thread 2 are rollbacked and the dosync in thread 2  is executed  
until the change can be succesfuly applied (in this example after the  
dosync of thread 1 is finished )?

Regards
   Roger


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Q: dosync semantics

2009-09-21 Thread Roger Gilliar
Hi !

Am 21.09.2009 um 15:55 schrieb Jarkko Oranen:

 In any case, the synchronisation guarantees that if you have a
 starting list A, either the remove or the append operation will be
 applied to it, producing A', and the remaining operation will be
 applied to A', producing the final value of the Ref.
--
Thanks.


 Oh, and rather than changing the discussion subject, please make a new
 topic. Changing the subject makes searches more difficult.

--
Sorry. I didn't know that this can cause  trouble. Hope it is ok to  
use reply right now .

Regards
   Roger


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Q: why doesn't this script terminate

2009-09-21 Thread Roger Gilliar

I call test.clj like this:

java -cp /Users/roger/Library/clojure/clojure-1.0.0.jar clojure.main  
test.clj


The script is:

(defn syncnow []
(println Hello World)
)


(dorun (pcalls syncnow syncnow syncnow))


But this script doesn't terminate. I have to press ctr-c to end this  
script. It seems that there a still some threads active. why ?

Regards
   Roger

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Q: is there a better way to do this

2009-09-21 Thread Roger Gilliar

This is some sort of repost from yesterday.  But I hope that this one  
describes my problem more precisely.
I have n threads that produce something. At some point in time a  
consumer starts and if the consumer starts, no more data should be  
produced.  Right now I can only come up with the following solution  
which I personally don't find very elegant.

Regards
   Roger

(def data (ref '()))

(def test-agent (agent '()))

(def processing-started (atom false))

(defn producer []
(doseq [i (take 1000 (repeat 1))]
(await test-agent)
(dosync
(if (= @processing-started false)
(do
(alter data conj i))


(defn IsTrue [d] true)

(defn setme [agent]
(loop []
(let[x1 (count @data)]
(. Thread (sleep 1500))
(let [x2 (count @data)]
(if (not= x1 x2)
(recur)
(dosync
(swap! processing-started 
IsTrue)
(println doesn't change 
anymore)
(println (count @data))
(. Thread (sleep 1500))
(println (count @data)) 
(ref-set data '(


(defn consumer []
(. Thread (sleep 350))
(send-off test-agent setme))

(dorun (apply pcalls (conj (take 200 (repeat producer)) consumer)))

(shutdown-agents)

(println @data)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: problem with threading and sql lib

2009-09-20 Thread Roger Gilliar


 Nothing leaps out at me as a likely cause of a dropped message.

-
The only reason I can think of: It could be a problem when the loading  
of the JDBC driver is happening inside a thread.  At least that would  
explain why calling

(with-connection db
   nil
)

before the thread is started, solves the problem.


 OTOH, the loop/recur at the end is probably better changed to a doseq.


Thanks for this tip.

Regards
   Roger

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Q: how to solve this concurrency problem ?

2009-09-20 Thread Roger Gilliar

Hi,

im not sure how to solve the following problem:

(defn parse [outstream-agent xml]
(let [content  (clojure.xml/parse (ByteArrayInputStream. (. xml  
getBytes)))
first-element   (:tag content) ]
(try
(if @*is-syncing*
(do
; iust continue f the agent is not 
running
(await *message-cache-agent* )
(if @*is-syncing*
(let [command (first-element 
*process-during-sync*)
  cache   (first-element 
*cache-during-sync*)
  ]
(if command
(command 
outstream-agent content)
(if cache

(cache-message content)
)
)
)
((first-element *messages*) 
outstream-agent content)
)
)
((first-element *messages*) outstream-agent 
content)
)
(catch Exception e
(do
(info (. e getMessage))
(fatal (str Unknown command: first-element))
false
)


The above code can be run by n threads. If the application is syncing  
certain messages are going to be cached. At some point the messages in  
the cache needed to be processed by a different thread (the *message- 
cache-agent* in this example). After that *is-syncing* is false. The  
problem with the above code is that messages could be added to the  
cache after the message-cache-agent is started so that is possible  
that some messages are not sent by the agent.

Right now I can only think of two solutions:

1.) the message-cache-agent checks for a certain amount of time if  
there are now new messages
2.)  I modify the code like this:

(if cache
(cache-message content)
(if (mesage-cache-agent-is-running)
(send-of *message-cache-agent* send-last-message-with 
content
)

The question  is.What would be the correct solution to this problem ?

Regards
   Roger

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: problem with threading and sql lib

2009-09-19 Thread Roger Gilliar
Not from my code.

Regards
   Roger


Am 19.09.2009 um 12:11 schrieb Christophe Grand:

 is db dynamically rebound?

 On Sat, Sep 19, 2009 at 7:07 AM, Roger Gilliar ro...@gilliar.de  
 wrote:

 Hi,

  re you opening something, using it to return a lazy sequence, and
  then closing it before consuming the sequence?


 No. I started with just opening the database connection in the handler
 function.

 Regards
   Roger






 -- 
 Professional: http://cgrand.net/ (fr)
 On Clojure: http://clj-me.blogspot.com/ (en)

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: problem with threading and sql lib

2009-09-19 Thread Roger Gilliar

 You mention threading in the subject and you have a (binding  
 [...] ...) form. Are you starting a thread, or communicating with  
 one, or using pmap, future, an agent, or etc. inside the binding,  
 and expecting the binding to affect the code that runs in the thread/ 
 map/future/agent?
 
Yes and no. The server created by the create-server calls  calls the  
handler :

(defn handle-client [in out]
(binding [
*in* (reader in)
]
(with-connection db
(let [outstream-agent (agent (writer out))

The above code is afaik executing in its own thread.   But since I'm  
just  starting to use clojure I'm not fully understanding whats going  
on inside the sql package so it could be that some of the things you  
mentioned are happening inside the sql lib.

The strange thing is that everything works, except that the first  
reply gets lost. It looks as if opening a database connection has some  
negative impact on printing to the outstream in this case.

Maybe some problem caused by initializing the JDBC driver from inside  
a thread ?


BTW: The reply function looks now like that:


(defn send-back-to-client [out xml]
(. out println xml)
(. out flush)   
)

(defn send-answers [messages]
(loop [message (first messages) remaining-messages (rest messages)]
(if message
(let [{outstream-agent :outstream-agent xml-message 
:message}  
message]
(send-off outstream-agent send-back-to-client 
xml-message)
(recur (first remaining-messages) (rest 
remaining-messages))


Regards
   Roger





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: problem with threading and sql lib

2009-09-18 Thread Roger Gilliar

Hi,

 re you opening something, using it to return a lazy sequence, and  
 then closing it before consuming the sequence?


No. I started with just opening the database connection in the handler  
function.

Regards
   Roger


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---