Skip to content

Commit

Permalink
prepped demo apps
Browse files Browse the repository at this point in the history
  • Loading branch information
adg committed Nov 24, 2010
1 parent 5498cb5 commit 6b59831
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion talk/code/2/store.go
Expand Up @@ -3,6 +3,7 @@ package main
import (
"gob"
"io"
"log"
"os"
"sync"
"time"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (s *URLStore) save() os.Error {
func (s *URLStore) saveLoop() {
for {
<-s.dirty
println("save")
log.Println("Saving")
s.save()
time.Sleep(saveTimeout)
}
Expand Down
15 changes: 15 additions & 0 deletions talk/code/3/demo.sh
@@ -0,0 +1,15 @@
#!/bin/sh

gomake
./goto -http=:8081 -rpc=true &
master_pid=$!
sleep 1
./goto -master=localhost:8081 &
slave_pid=$!
echo "Running master on :8081, slave on :8080."
echo "Visit: http://localhost:8080/add"
echo "Press enter to shut down"
read
kill $master_pid
kill $slave_pid

4 changes: 4 additions & 0 deletions talk/code/3/main.go
Expand Up @@ -36,6 +36,10 @@ func main() {

func Redirect(w http.ResponseWriter, r *http.Request) {
key := r.URL.Path[1:]
if key == "" || key == "favicon.ico" {
http.NotFound(w, r)
return
}
var url string
if err := store.Get(&key, &url); err != nil {
http.Error(w, err.String(), http.StatusInternalServerError)
Expand Down
5 changes: 5 additions & 0 deletions talk/code/3/store.go
Expand Up @@ -39,6 +39,7 @@ func NewURLStore(filename string) *URLStore {
}

func (s *URLStore) Get(key, url *string) os.Error {
log.Println("URLStore: Get", *key)
if u, ok := s.urls.Get(*key); ok {
*url = u
return nil
Expand All @@ -47,6 +48,7 @@ func (s *URLStore) Get(key, url *string) os.Error {
}

func (s *URLStore) Put(url, key *string) os.Error {
log.Println("URLStore: Put", *url)
s.mu.Lock()
for {
*key = genKey(s.count)
Expand Down Expand Up @@ -106,8 +108,10 @@ func NewProxyStore(addr string) *ProxyStore {
func (s *ProxyStore) Get(key, url *string) os.Error {
if u, ok := s.urls.Get(*key); ok {
*url = u
log.Println("ProxyStore: Get cache hit", *key)
return nil
}
log.Println("ProxyStore: Get cache miss", *key)
err := s.client.Call("Store.Get", key, url)
if err == nil {
s.urls.Set(*key, *url)
Expand All @@ -116,6 +120,7 @@ func (s *ProxyStore) Get(key, url *string) os.Error {
}

func (s *ProxyStore) Put(url, key *string) os.Error {
log.Println("ProxyStore: Put", *url)
err := s.client.Call("Store.Put", url, key)
if err == nil {
s.urls.Set(*key, *url)
Expand Down

0 comments on commit 6b59831

Please sign in to comment.