This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.acme; | |
import com.prevoty.*; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import java.io.IOException; | |
import java.io.PrintWriter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ( | |
RPC struct { | |
cache map[string]string | |
requests *Requests | |
mu *sync.RWMutex | |
} | |
CacheItem struct { | |
Key string | |
Value string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func NewRPC() *RPC { | |
return &RPC{ | |
cache: make(map[string]string), | |
requests: &Requests{}, | |
mu: &sync.RWMutex{}, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (r *RPC) Get(key string, resp *CacheItem) (err error) { | |
r.mu.RLock() | |
defer r.mu.RUnlock() | |
cacheValue, found := r.cache[key] | |
if !found { | |
return NotFoundError | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (r *RPC) Put(item *CacheItem, ack *bool) error { | |
r.mu.Lock() | |
defer r.mu.Unlock() | |
r.cache[item.Key] = item.Value | |
*ack = true | |
r.requests.Put++ | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (r *RPC) Delete(key string, ack *bool) error { | |
r.mu.Lock() | |
defer r.mu.Unlock() | |
var found bool | |
_, found = r.cache[key] | |
if !found { | |
return NotFoundError | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (r *RPC) Clear(skip bool, ack *bool) error { | |
r.mu.Lock() | |
defer r.mu.Unlock() | |
r.cache = make(map[string]string) | |
*ack = true | |
r.requests.Clear++ | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (r *RPC) Stats(skip bool, requests *Requests) error { | |
*requests = *r.requests | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net" | |
"net/rpc" | |
"runtime" | |
) | |
func init() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ( | |
Client struct { | |
connection *rpc.Client | |
} | |
) | |
func NewClient(dsn string, timeout time.Duration) (*Client, error) { | |
connection, err := net.DialTimeout("tcp", dsn, timeout) | |
if err != nil { | |
return nil, err |
OlderNewer