예제 #1
0
func (f *pushDatabaseOpts) ModifyDeliveryPoint(dp *push.DeliveryPoint) error {
	if len(dp.Name()) == 0 {
		return nil
	}
	f.dblock.Lock()
	defer f.dblock.Unlock()
	return addErrorSource("ModifyDeliveryPoint", f.db.SetDeliveryPoint(dp))
}
예제 #2
0
func (f *pushDatabaseOpts) AddDeliveryPointToService(service string,
	subscriber string,
	delivery_point *push.DeliveryPoint) (*push.PushServiceProvider, error) {
	if delivery_point == nil {
		return nil, nil
	}
	if len(delivery_point.Name()) == 0 {
		return nil, errors.New("InvalidDeliveryPoint")
	}
	f.dblock.Lock()
	defer f.dblock.Unlock()
	pspnames, err := f.db.GetPushServiceProvidersByService(service)
	if err != nil {
		return nil, fmt.Errorf("Cannot list services for %s: %v", service, err)
	}
	if pspnames == nil {
		return nil, errors.New(fmt.Sprintf("Cannot Find Service %s", service))
	}

	for _, pspname := range pspnames {
		psp, e := f.db.GetPushServiceProvider(pspname)
		if e != nil {
			return nil, fmt.Errorf("Failed to get information for psp %s: %v", pspname, e)
		}
		if psp == nil {
			continue
		}
		if psp.PushServiceName() == delivery_point.PushServiceName() {
			err = f.db.SetDeliveryPoint(delivery_point)
			if err != nil {
				return nil, fmt.Errorf("Failed to save new info for delivery point: %v", err)
			}
			err = f.db.AddDeliveryPointToServiceSubscriber(service, subscriber, delivery_point.Name())
			if err != nil {
				return nil, fmt.Errorf("Failed to add delivery point to subscriber: %v", err)
			}
			err = f.db.SetPushServiceProviderOfServiceDeliveryPoint(service, delivery_point.Name(), psp.Name())
			if err != nil {
				return nil, fmt.Errorf("Failed to set psp of delivery point: %v", err)
			}
			return psp, nil
		}
	}
	return nil, errors.New(fmt.Sprintf("Cannot Find Push Service Provider with Type %s", delivery_point.PushServiceName()))
}
예제 #3
0
func (f *pushDatabaseOpts) RemoveDeliveryPointFromService(service string,
	subscriber string,
	delivery_point *push.DeliveryPoint) error {
	if delivery_point.Name() == "" {
		return errors.New("InvalidDeliveryPoint")
	}
	f.dblock.Lock()
	defer f.dblock.Unlock()
	err := f.db.RemoveDeliveryPointFromServiceSubscriber(service, subscriber, delivery_point.Name())
	if err != nil {
		return fmt.Errorf("Failed to remove delivery point: %v", err)
	}
	err = f.db.RemovePushServiceProviderOfServiceDeliveryPoint(service, delivery_point.Name())
	if err != nil {
		return fmt.Errorf("Failed to remove psp info for delivery point: %v", err)
	}
	return nil
}
예제 #4
0
func (cdb *pushRawDatabaseCache) SetDeliveryPoint(dp *push.DeliveryPoint) error {
	cdb.dpCache.Set(dp.Name(), dp)
	return nil
}
예제 #5
0
func (r *PushRedisDB) SetDeliveryPoint(dp *push.DeliveryPoint) error {
	err := r.client.Set(DELIVERY_POINT_PREFIX+dp.Name(), deliveryPointToValue(dp), 0).Err()
	return err
}
예제 #6
0
func deliveryPointToValue(dp *push.DeliveryPoint) []byte {
	return dp.Marshal()
}