Skip to content

Commit

Permalink
added nrdp parameter. fixed issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
monnand committed Apr 19, 2013
1 parent d5764ef commit 0a2fadd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pushbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ func (self *PushBackEnd) collectResult(reqId string, service string, resChan <-c
}
}

func (self *PushBackEnd) NumberOfDeliveryPoints(service, sub string, logger Logger) int {
pspDpList, err := self.db.GetPushServiceProviderDeliveryPointPairs(service, sub)
if err != nil {
logger.Errorf("Query=NumberOfDeliveryPoints Service=%v Subscriber=%v Failed: Database Error %v", service, sub, err)
return 0
}
return len(pspDpList)
}

func (self *PushBackEnd) Push(reqId string, service string, subs []string, notif *Notification, logger Logger) {
self.pushImpl(reqId, service, subs, notif, logger, nil, nil, 0*time.Second)
}
Expand Down
29 changes: 29 additions & 0 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
PUSH_NOTIFICATION_URL = "/push"
STOP_PROGRAM_URL = "/stop"
VERSION_INFO_URL = "/version"
QUERY_NUMBER_OF_DELIVERY_POINTS_URL = "/nrdp"
)

var validServicePattern *regexp.Regexp
Expand Down Expand Up @@ -249,10 +250,37 @@ func (self *RestAPI) stop(w io.Writer, remoteAddr string) {
return
}

func (self *RestAPI) numberOfDeliveryPoints(kv map[string][]string, logger log.Logger, remoteAddr string) int {
ret := 0
ss, ok := kv["service"]
if !ok {
return ret
}
if len(ss) == 0 {
return ret
}
service := ss[0]
subs, ok := kv["subscriber"]
if !ok {
return ret
}
if len(subs) == 0 {
return ret
}
sub := subs[0]
ret = self.backend.NumberOfDeliveryPoints(service, sub, logger)
return ret
}

func (self *RestAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
remoteAddr := r.RemoteAddr
switch r.URL.Path {
case QUERY_NUMBER_OF_DELIVERY_POINTS_URL:
r.ParseForm()
n := self.numberOfDeliveryPoints(r.Form, self.loggers[LOGGER_WEB], remoteAddr)
fmt.Fprintf(w, "%v\r\n", n)
return
case VERSION_INFO_URL:
fmt.Fprintf(w, "%v\r\n", self.version)
self.loggers[LOGGER_WEB].Infof("Checked version from %v", remoteAddr)
Expand Down Expand Up @@ -309,6 +337,7 @@ func (self *RestAPI) Run(addr string, stopChan chan<- bool) {
http.Handle(REMOVE_DELIVERY_POINT_FROM_SERVICE_URL, self)
http.Handle(REMOVE_PUSH_SERVICE_PROVIDER_TO_SERVICE_URL, self)
http.Handle(PUSH_NOTIFICATION_URL, self)
http.Handle(QUERY_NUMBER_OF_DELIVERY_POINTS_URL, self)
self.stopChan = stopChan
err := http.ListenAndServe(addr, nil)
if err != nil {
Expand Down

0 comments on commit 0a2fadd

Please sign in to comment.